springboot項目接入sap與部署到docker遇到的問題實錄

前言

本文例子來源於某個業務團隊,本文主要記錄在協助他們部署接入sap遇到的問題,且只記錄解決問題的答案,不說明原理。java

問題實錄

一、問題一: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

不過咱們沒采用這種方案spring

解決方案二:指定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,形以下docker

<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/app

問題二:java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path

由於項目是部署到docker裏面去,所以本文只寫基於docker的解決方案dom

解決方案以下:maven

在dockerFile裏面指定LD_LIBRARY_PATH環境變量,形以下spring-boot

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" ]

總結

原本不想寫這篇,但從業務團隊那邊瞭解到,他們當時百度了好久都沒找到合適的答案。所以就記錄下這篇文章,看下可否對有遇到此問題的朋友提供一點解決思路ui

相關文章
相關標籤/搜索