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

環境:java

springboot + kafka + ES 。。。。。。spring

maven3.6apache

jdk8springboot

問題是 jar包啓動失敗報錯,錯誤以下:mybatis

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文件以下elasticsearch

<!-- 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>

錯誤緣由分析:maven

Pom中採用了maven-shade-plugin,最終生成了fat包,超過Spring Boot Loader的上限。所以,在B模塊的Pom中直接移除了maven-shade-plugin插件,使得該依賴大小符合要求。spring-boot

解決辦法:測試

註釋掉紅圈的plugin。ui

相關文章
相關標籤/搜索