Maven无效的LOC头(坏签名)

我得到了下面的exception,当我运行我的mvn install.I甚至删除了本地仓库,并再次运行得到相同的exception。

[错误]无法执行目标org.apache.maven.plugins:maven-shade-plugin:2.1:阴影(默认)在项目cores-batch:创build阴影jar时出错:无效的LOC头(坏签名) – > [Help 1 ]

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.1</version> <configuration> <skipTests>true</skipTests> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <artifactSet> <excludes> <exclude>commons-logging:commons-logging:jar:*</exclude> </excludes> </artifactSet> <filters> <filter> <artifact>*:*</artifact> <excludes> <!-- workaround for a spring issues --> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> <!-- don't want to pick up any other log4j.xml --> <exclude>log4j.xml</exclude> </excludes> </filter> </filters> <!-- May be needed to work around another issue in Spring --> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.handlers</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.schemas</resource> </transformer> </transformers> </configuration> </execution> </executions> </plugin> 

错误:

 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.1:shade (default) on project cores-batch: Error creating shaded jar: invalid LOC header (bad signature) -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.1:shade (default) on project cores-batch: Error creating shaded jar: invalid LOC header (bad signature) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) Caused by: org.apache.maven.plugin.MojoExecutionException: Error creating shaded jar: invalid LOC header (bad signature) at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:528) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) ... 19 more Caused by: java.util.zip.ZipException: invalid LOC header (bad signature) at java.util.zip.ZipFile.read(Native Method) at java.util.zip.ZipFile.access$1400(ZipFile.java:56) at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:679) at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(ZipFile.java:415) at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158) at java.io.FilterInputStream.read(FilterInputStream.java:107) at org.codehaus.plexus.util.IOUtil.copy(IOUtil.java:189) at org.codehaus.plexus.util.IOUtil.copy(IOUtil.java:175) at org.apache.maven.plugins.shade.DefaultShader.addResource(DefaultShader.java:427) at org.apache.maven.plugins.shade.DefaultShader.shade(DefaultShader.java:186) at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:458) ... 21 more [ERROR] [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 

主要的问题是jar子损坏。

要find损坏的文件,需要在Eclipse的断点视图或首选的IDE中添加Javaexception断点 ,selectjava.util.zip.ZipException类,然后重新启动Tomcat实例。

当JVM在ZipException断点处挂起时,您必须转到堆栈跟踪中的JarFile.getManifestFromReference() ,并检查属性name以查看文件名。

之后,您应该从文件系统中删除该文件,然后右键单击您的项目,selectMaven,更新项目,检查强制更新快照/释放。

该jar文件可能已损坏。 尝试删除您的内容

  C:\Users\[username]\.m2\repository folder. 

然后右键单击您的项目,selectMaven,更新项目,检查强制更新快照/释放。

从gsitgithub / find-currupt-jars.txt中 ,以下命令列出了存储库中所有损坏的jar文件:

 find /home/me/.m2/repository/ -name "*jar" | xargs -L 1 zip -T | grep error | grep invalid 

您可以删除损坏的jar文件,并重新编译项目。

示例输出:

 warning [/cygdrive/J/repo/net/java/dev/jna/jna/4.1.0/jna-4.1.0.jar]: 98304 extra bytes at beginning or within zipfile (attempting to process anyway) file #1: bad zipfile offset (local header sig): 98304 (attempting to re-compensate) zip error: Zip file invalid, could not spawn unzip, or wrong unzip (original files unmodified) 

看起来你的pom文件中maven编译器的configuration问题。 Java源和目标的默认版本是1.5,甚至使用JDK有更高的版本。

为了解决这个问题,添加更高java版本的maven编译器插件configuration部分,例如:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> 

更多信息查看这些链接:

maven编译器

错误报告

我想给我的练习。

使用你喜欢的IDE,例如在这里举例来说:

  1. 在exception堆栈中find合适的位置
  2. 设置条件断点
  3. debugging它
  4. 它将在exception之前打印损坏的jar

在这里输入图像描述

我的解决scheme是用-X运行mvn

 $ mvn package -X 

然后回头看看输出,直到看到失败,然后继续前进,直到看到mvn试图处理的最后一个jar文件:

 ... ... <<output ommitted>> ... [DEBUG] Processing JAR /Users/snowch/.m2/repository/org/eclipse/jetty/jetty-server/9.2.15.v20160210/jetty-server-9.2.15.v20160210.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.607 s [INFO] Finished at: 2017-10-04T14:30:13+01:00 [INFO] Final Memory: 23M/370M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.1.0:shade (default) on project kafka-connect-on-cloud-foundry: Error creating shaded jar: invalid LOC header (bad signature) -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.1.0:shade (default) on project kafka-connect-on-cloud-foundry: Error creating shaded jar: invalid LOC header (bad signature) 

查看失败之前的最后一个jar,并从本地存储库中删除它,即

 $ rm -rf /Users/snowch/.m2/repository/org/eclipse/jetty/jetty-server/9.2.15.v20160210/ 

大多数情况下,这是因为损坏的zar更新maven中央存储库URL在pom.xml文件解决了我的问题,您可以使用此urlhttps://repo.maven.apache.org/maven2/但在此之前删除文件在.m2目录希望这有助于

使用选项“-e -X”构build项目,找出损坏的jar文件,并从本地存储库中删除jar文件。