springBoot项目替换lib下的依赖jar包 Unable to open nested entry BOOT-INF/lib/

问题:

springboot项目在使用压缩软件替换lib下的依赖包后,启动报错,报错内容如下:

PS D:\ttmp> java -jar .\epayBusiness-2.0.2-SNAPSHOT.jar
Exception in thread "main" java.lang.IllegalStateException: Failed to get nested archive for entry BOOT-INF/lib/ojdbc7-12.1.0.2.0.jar
        at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:109)
        at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchives(JarFileArchive.java:87)
        at org.springframework.boot.loader.ExecutableArchiveLauncher.getClassPathArchives(ExecutableArchiveLauncher.java:72)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:49)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.io.IOException: Unable to open nested jar file 'BOOT-INF/lib/ojdbc7-12.1.0.2.0.jar'
        at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:252)
        at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:237)
        at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:104)
        ... 4 more
Caused by: java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/ojdbc7-12.1.0.2.0.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file
        at org.springframework.boot.loader.jar.JarFile.createJarFileFromFileEntry(JarFile.java:285)
        at org.springframework.boot.loader.jar.JarFile.createJarFileFromEntry(JarFile.java:260)
        at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:248)
        ... 6 more
原因:

替换或者导入jar包时,jar包被自动压缩,springboot规定嵌套的jar包不能在被压缩的情况下存储。

解决(本文以升级ojdbc包为例):

使用jar命令解压jar包,在压缩包外重新替换jar包,在进行压缩。

步骤1:解压jar包   jar -xvf  *.jar

PS D:\ttmp> jar -xvf *.jar
  已创建: META-INF/
  已解压: META-INF/MANIFEST.MF
  已创建: BOOT-INF/
  已创建: BOOT-INF/classes/
  已创建: BOOT-INF/classes/com/
步骤2:替换jar包

rm -rf BOOT-INF/lib/ojdbc14-10.2.0.4.0.jar
mv ojdbc7-12.1.0.2.0.jar BOOT-INF/lib/
 
步骤3:重新压缩jar

 jar -cfM0 new.jar BOOT-INF/ META-INF/ org/
 
 

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页