前言
本文例子来源于某个业务团队,本文主要记录在协助他们部署接入sap遇到的问题,且只记录解决问题的答案,不说明原理。
问题实录
1、问题一:Illegal JCo archive "sapjco-1.0.jar". It is not allowed to rename or repackage the original archive "sapjco3.jar"
解决方案一:手动项目中将sapjco-1.0.jar重名为sapjco3.jar
不过我们没采用这种方案
解决方案二:指定maven的scope为system,形如下
<dependency>
<groupId>com.sap</groupId>
<artifactId>sapjco</artifactId>
<version>${sap.version}</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/sapjco3.jar</systemPath>
</dependency>
然后指定resources,形如下
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>${project.basedir}/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.basedir}/lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}/lib</directory>
<targetPath>BOOT-INF</targetPath>
<includes>
<include>**/*.so</include>
<include>**/*.dll</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<!--<targetPath>BOOT-INF/classes/</targetPath>-->
<includes>
<include>**/*.yml</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
这个的作用是将sapjco3.jar打进BOOT-INF/lib/
问题二:java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path
因为项目是部署到docker里面去,因此本文只写基于docker的解决方案
解决方案如下:
在dockerFile里面指定LD_LIBRARY_PATH环境变量,形如下
FROM adoptopenjdk/openjdk8
VOLUME /tmp
#ENV JAVA_OPTS="-Dcom.sun.management.jmxremote.port=39083 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
ENV JAVA_OPTS=""
ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
COPY localtime /etc/localtime
RUN echo "Asia/Shanghai" > /etc/timezone
COPY hello-biz/target/hello-biz-*.jar app.jar
COPY hello-biz/lib/libsapjco3.so /usr/local/lib/libsapjco3.so
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
总结
本来不想写这篇,但从业务团队那边了解到,他们当时百度了很久都没找到合适的答案。因此就记录下这篇文章,看下能否对有遇到此问题的朋友提供一点解决思路
网友评论