环境:
springboot + kafka + ES 。。。。。。
maven3.6
jdk8
问题是 jar包启动失败报错,错误如下:
1Exception in thread "main" java.lang.IllegalStateException: Failed to get nested archive for entry BOOT-INF/lib/spring-kafka-2.2.7.RELEASE.jar 2 at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:108) 3 at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchives(JarFileArchive.java:86) 4 at org.springframework.boot.loader.ExecutableArchiveLauncher.getClassPathArchives(ExecutableArchiveLauncher.java:70) 5 at org.springframework.boot.loader.Launcher.launch(Launcher.java:49) 6 at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) 7Caused by: java.io.IOException: Unable to open nested jar file 'BOOT-INF/lib/spring-kafka-2.2.7.RELEASE.jar' 8 at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:256) 9 at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:241) 10 at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:103) 11 ... 4 more 12Caused by: java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/spring-kafka-2.2.7.RELEASE.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 13 at org.springframework.boot.loader.jar.JarFile.createJarFileFromFileEntry(JarFile.java:284) 14 at org.springframework.boot.loader.jar.JarFile.createJarFileFromEntry(JarFile.java:264) 15 at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:252) 16 ... 6 more
pom.xml文件如下
1<!-- spring-boot-starter-data-elasticsearch --> 2 <dependency> 3 <groupId>org.springframework.boot</groupId> 4 <artifactId>spring-boot-starter-data-elasticsearch</artifactId> 5 </dependency> 6 <!-- elasticsearch-rest-high-level-client --> 7 <dependency> 8 <groupId>org.elasticsearch.client</groupId> 9 <artifactId>elasticsearch-rest-high-level-client</artifactId> 10 </dependency> 11 12 <!--swagger2--> 13 <dependency> 14 <groupId>io.springfox</groupId> 15 <artifactId>springfox-swagger2</artifactId> 16 <version>2.6.1</version> 17 </dependency> 18 19 <dependency> 20 <groupId>io.springfox</groupId> 21 <artifactId>springfox-swagger-ui</artifactId> 22 <version>2.6.1</version> 23 </dependency> 24 25 <!-- devtools --> 26 <dependency> 27 <groupId>org.springframework.boot</groupId> 28 <artifactId>spring-boot-devtools</artifactId> 29 <scope>runtime</scope> 30 <optional>true</optional> 31 </dependency> 32 <!--sofaboot测试插件--> 33 <dependency> 34 <groupId>com.alipay.sofa</groupId> 35 <artifactId>test-sofa-boot-starter</artifactId> 36 </dependency> 37 <dependency> 38 <groupId>org.springframework.boot</groupId> 39 <artifactId>spring-boot-starter-test</artifactId> 40 <scope>test</scope> 41 <exclusions> 42 <exclusion> 43 <groupId>org.junit.vintage</groupId> 44 <artifactId>junit-vintage-engine</artifactId> 45 </exclusion> 46 </exclusions> 47 </dependency> 48 <!-- mybatis --> 49 <dependency> 50 <groupId>org.mybatis.spring.boot</groupId> 51 <artifactId>mybatis-spring-boot-starter</artifactId> 52 <version>1.3.2</version> 53 </dependency> 54 </dependencies> 55 <build> 56 <plugins> 57 <plugin> 58 <groupId>org.springframework.boot</groupId> 59 <artifactId>spring-boot-maven-plugin</artifactId> 60 </plugin> 61 <plugin> 62 <groupId>org.apache.maven.plugins</groupId> 63 <artifactId>maven-shade-plugin</artifactId> 64 <version>3.1.0</version> 65 <executions> 66 <execution> 67 <phase>package</phase> 68 <goals><goal>shade</goal></goals> 69 <configuration> 70 <relocations> 71 <relocation> 72 <pattern>org.apache.http</pattern> 73 <shadedPattern>hidden.org.apache.http</shadedPattern> 74 </relocation> 75 <relocation> 76 <pattern>org.apache.logging</pattern> 77 <shadedPattern>hidden.org.apache.logging</shadedPattern> 78 </relocation> 79 <relocation> 80 <pattern>org.apache.commons.codec</pattern> 81 <shadedPattern>hidden.org.apache.commons.codec</shadedPattern> 82 </relocation> 83 <relocation> 84 <pattern>org.apache.commons.logging</pattern> 85 <shadedPattern>hidden.org.apache.commons.logging</shadedPattern> 86 </relocation> 87 </relocations> 88 </configuration> 89 </execution> 90 </executions> 91 </plugin> 92 </plugins> 93 </build> 94 <repositories>
错误原因分析:
Pom中采用了maven-shade-plugin,最终生成了fat包,超过Spring Boot Loader的上限。因此,在B模块的Pom中直接移除了maven-shade-plugin插件,使得该依赖大小符合要求。
解决办法:
注释掉红圈的plugin。
