PACT Maven-SpringBoot研讨会步骤1失败,出现IlLegalStateException:无法获取Boot-INF/lib/Logback-Classic-1.2.3.jar条目的嵌套归档文件

qyyhg6bp  于 2022-10-26  发布在  Maven
关注(0)|答案(1)|浏览(163)

我正在尝试执行Pact Maven-Springboot研讨会中的步骤,但在运行以下命令时,在步骤1得到此错误:Java-jar Target/product-Catalogue-0.0.1-SNAPSHOT.jar:

C:\Users\57046\git\pact-workshop-Maven-Springboot-JUnit5\consumer>java -jar target/product-catalogue-0.0.1-SNAPSHOT.jar
Exception in thread "main" java.lang.IllegalStateException: Failed to get nested archive for entry BOOT-INF/lib/logback-classic-1.2.3.jar
        at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:104)
        at org.springframework.boot.loader.archive.JarFileArchive$NestedArchiveIterator.adapt(JarFileArchive.java:237)
        at org.springframework.boot.loader.archive.JarFileArchive$NestedArchiveIterator.adapt(JarFileArchive.java:228)
        at org.springframework.boot.loader.archive.JarFileArchive$AbstractIterator.next(JarFileArchive.java:189)
        at org.springframework.boot.loader.ExecutableArchiveLauncher.createClassLoader(ExecutableArchiveLauncher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:55)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: java.io.IOException: Unable to open nested jar file 'BOOT-INF/lib/logback-classic-1.2.3.jar'
        at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:288)
        at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:274)
        at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:100)
        ... 6 more
Caused by: java.lang.IndexOutOfBoundsException
        at org.springframework.boot.loader.jar.AsciiBytes.<init>(AsciiBytes.java:73)
        at org.springframework.boot.loader.jar.CentralDirectoryFileHeader.load(CentralDirectoryFileHeader.java:85)
        at org.springframework.boot.loader.jar.CentralDirectoryParser.parseEntries(CentralDirectoryParser.java:68)
        at org.springframework.boot.loader.jar.CentralDirectoryParser.parse(CentralDirectoryParser.java:57)
        at org.springframework.boot.loader.jar.JarFile.<init>(JarFile.java:137)
        at org.springframework.boot.loader.jar.JarFile.<init>(JarFile.java:123)
        at org.springframework.boot.loader.jar.JarFile.createJarFileFromFileEntry(JarFile.java:319)
        at org.springframework.boot.loader.jar.JarFile.createJarFileFromEntry(JarFile.java:296)
        at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:285)
        ... 8 more

按照Stephen的建议,我检查了提到的JAR是否损坏。MVN从属关系:分析打印了以下内容:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  29.455 s
[INFO] Finished at: 2022-10-11T15:26:10+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.1.2:analyze (default-cli) on project product-catalogue: Cannot analyze dependencies: invalid CEN header (bad signature) -> [Help 1]

我删除了JAR文件,运行mvnw Verify(没有错误,并记录了JAR已再次下载),然后再次运行MVN Dependency:Analyze,结果是:

[WARNING] Used undeclared dependencies found:
[WARNING]    org.springframework.boot:spring-boot:jar:2.4.3:compile
[WARNING]    org.springframework:spring-web:jar:5.3.4:compile
[WARNING]    org.springframework:spring-beans:jar:5.3.4:compile
[WARNING]    org.springframework:spring-context:jar:5.3.4:compile
[WARNING]    org.springframework.boot:spring-boot-autoconfigure:jar:2.4.3:compile
[WARNING] Unused declared dependencies found:
[WARNING]    org.springframework.boot:spring-boot-starter-web:jar:2.4.3:compile
[WARNING]    org.springframework.boot:spring-boot-starter-thymeleaf:jar:2.4.3:compile
[WARNING]    org.springframework.boot:spring-boot-starter-test:jar:2.4.3:test
[WARNING]    org.projectlombok:lombok:jar:1.18.16:provided
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.768 s
[INFO] Finished at: 2022-10-11T16:00:05+03:00

但是,当我尝试运行代码时,仍然收到相同的异常。
按照another suggestion的要求,我运行了MVN SpringBoot:Run,但得到:

C:\Users\57046\git\pact-workshop-Maven-Springboot-JUnit5\consumer>mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< io.pact.workshop:product-catalogue >-----------------
[INFO] Building product-catalogue 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.4.3:run (default-cli) > test-compile @ product-catalogue >>>
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ product-catalogue ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ product-catalogue ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ product-catalogue ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory C:\Users\57046\git\pact-workshop-Maven-Springboot-JUnit5\consumer\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ product-catalogue ---
[INFO] No sources to compile
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.4.3:run (default-cli) < test-compile @ product-catalogue <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.3:run (default-cli) @ product-catalogue ---
[INFO] Attaching agents: []
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
        at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:39)
        at org.apache.commons.logging.LogAdapter$Log4jLog.<init>(LogAdapter.java:165)
        at org.apache.commons.logging.LogAdapter$Log4jAdapter.createLog(LogAdapter.java:122)
        at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:89)
        at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67)
        at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:59)
        at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:203)
        at io.pact.workshop.product_catalogue.Application.main(Application.java:12)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 8 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.030 s
[INFO] Finished at: 2022-10-11T16:18:48+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.3:run (default-cli) on project product-catalogue: Application finished with exit code: 1 -> [Help 1]

这更加令人困惑,因为它为另一个类获取了NoClassDefFoundError。

nukf8bse

nukf8bse1#

我认为Consumer\pom.xml中缺少一个条目。当我添加此依赖项时:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-logging</artifactId> 
</dependency>

根据this answer,它开始工作。

相关问题