zoukankan      html  css  js  c++  java
  • springboot maven项目打包SAPJCO3.JAR

    下载SAPJCO3

    SAPJCO3 3.1.2

    springboot项目加入本地JAR包依赖

    pom.xml

    <!-- 引入sapjco3.jar -->
    <dependency>
        <groupId>com.sap.conn.jco</groupId>
        <artifactId>sapjco3</artifactId>
        <version>3.1.2</version>
        <scope>system</scope>
        <systemPath>C:/SAPJCO/sapjco3.jar</systemPath>
    </dependency>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!-- 加入以下代码,否则不会将dependency.scope=system的依赖项打包 -->
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    启动报错

    Caused by: java.lang.ExceptionInInitializerError:
     JCo initialization failed with java.lang.ExceptionInInitializerError:
      Illegal JCo archive "sapjco3-3.1.2.jar".
       It is not allowed to rename or repackage the original archive "sapjco3.jar".
    

    原因分析

    1. 使用maven打包时会将依赖项jar包改名加上版本号
      打包后可以看到jar包中对应文件为BOOT-INFlibsapjco3-3.1.2.jar
    2. sapjco3.0.11之后版本加入对sapjco3.jar包校验,如果文件名不符合启动项目报错
      源码:com.sap.conn.jco.rt.DefaultJCoRuntime
    ...
    private static String loadJCoLibrary() {
    ...
    if (!osArch.equals("sapjco3.jar") 
    	&& !osArch.startsWith("com.sap.conn.jco") 
    	&& Package.getPackage("org.apache.maven.surefire.booter") == null 
    	&& Package.getPackage("org.eclipse.jdt.internal.junit.runner") == null) {
    	throw new ExceptionInInitializerError("Illegal JCo archive "" + osArch + "". It is not allowed to rename or repackage the original archive "" + "sapjco3.jar" + "".");
    	}
    ...
    }
    ...
    

    解决

    打包完成后将jar包对应文件改名为sapjco.jar即可

    优化

    下面文章中使用了另一种方法打包避免改名问题
    springboot maven项目引入并打包本地JAR

  • 相关阅读:
    vue框架组件id获取
    Proxy 与 Object.defineProperty 优劣对比
    vue 父组件监听子组件生命周期
    Vue 的父组件和子组件生命周期钩子函数执行顺序
    k8s 集群部署--学习
    Linux命令:ipcs/ipcrm命令
    Python模块
    XAMPP+TestLink
    bug管理工具
    批量管理工具:pssh/ansible
  • 原文地址:https://www.cnblogs.com/luguojun/p/14294732.html
Copyright © 2011-2022 走看看