Failed to get nested archive for entry BOOT-INF/lib/spring-kafka-2.2.7.RELEASE.jar

Posted lf_victor17919

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Failed to get nested archive for entry BOOT-INF/lib/spring-kafka-2.2.7.RELEASE.jar相关的知识,希望对你有一定的参考价值。

环境:

springboot + kafka + ES 。。。。。。

maven3.6

jdk8

问题是 jar包启动失败报错,错误如下:

Exception in thread "main" java.lang.IllegalStateException: Failed to get nested archive for entry BOOT-INF/lib/spring-kafka-2.2.7.RELEASE.jar
        at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:108)
        at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchives(JarFileArchive.java:86)
        at org.springframework.boot.loader.ExecutableArchiveLauncher.getClassPathArchives(ExecutableArchiveLauncher.java:70)
        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/spring-kafka-2.2.7.RELEASE.jar\'
        at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:256)
        at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:241)
        at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:103)
        ... 4 more
Caused 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
        at org.springframework.boot.loader.jar.JarFile.createJarFileFromFileEntry(JarFile.java:284)
        at org.springframework.boot.loader.jar.JarFile.createJarFileFromEntry(JarFile.java:264)
        at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:252)
        ... 6 more

pom.xml文件如下

        <!-- spring-boot-starter-data-elasticsearch -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
        <!-- elasticsearch-rest-high-level-client -->
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
        </dependency>

        <!--swagger2-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
        </dependency>

        <!-- devtools -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <!--sofaboot测试插件-->
        <dependency>
            <groupId>com.alipay.sofa</groupId>
            <artifactId>test-sofa-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- mybatis -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
               <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.1.0</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals><goal>shade</goal></goals>
                            <configuration>
                                <relocations>
                                    <relocation>
                                        <pattern>org.apache.http</pattern>
                                        <shadedPattern>hidden.org.apache.http</shadedPattern>
                                    </relocation>
                                    <relocation>
                                        <pattern>org.apache.logging</pattern>
                                        <shadedPattern>hidden.org.apache.logging</shadedPattern>
                                    </relocation>
                                    <relocation>
                                        <pattern>org.apache.commons.codec</pattern>
                                        <shadedPattern>hidden.org.apache.commons.codec</shadedPattern>
                                    </relocation>
                                    <relocation>
                                        <pattern>org.apache.commons.logging</pattern>
                                        <shadedPattern>hidden.org.apache.commons.logging</shadedPattern>
                                    </relocation>
                                </relocations>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
    </build>
    <repositories>

错误原因分析:

Pom中采用了maven-shade-plugin,最终生成了fat包,超过Spring Boot Loader的上限。因此,在B模块的Pom中直接移除了maven-shade-plugin插件,使得该依赖大小符合要求。

解决办法:

注释掉红圈的plugin。

 

 

以上是关于Failed to get nested archive for entry BOOT-INF/lib/spring-kafka-2.2.7.RELEASE.jar的主要内容,如果未能解决你的问题,请参考以下文章

Failed to get nested archive for entry BOOT-INF/lib/spring-kafka-2.2.7.RELEASE.jar

Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPointerEx

SpringBoot解决Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.N

解决报错Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPoint

Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPointerEx

CloudAlibaba下报Failed to start bean ‘webServerStartStop‘; nested exception is java.lang.reflect异常解决