springboot maven项目打包SAPJCO3.JAR
下载SAPJCO3
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".
原因分析
- 使用maven打包时会将依赖项jar包改名加上版本号
打包后可以看到jar包中对应文件为BOOT-INF\lib\sapjco3-3.1.2.jar - 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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?