运行mvn install
时,我收到以下异常。我甚至删除了本地存储库并再次运行获得相同的异常。
[错误]无法执行目标 org.apache.maven.plugins:maven-shade-plugin:2.1:shade(默认)on project cores-batch:创建着色jar时出错:LOC标头无效 (签名不好) - > [帮助1]
<?xml version="1.0" encoding="UTF-8"?>
<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
答案 0 :(得分:197)
jar文件可能已损坏。尝试删除以下文件夹的内容:
C:\Users\[username]\.m2\repository
然后右键单击您的项目,选择Maven,更新项目,选中强制更新快照/版本。
答案 1 :(得分:107)
主要问题是罐子腐烂。
要查找损坏的文件,需要在Eclipse的Breakpoints视图或首选IDE中添加 Java Exception Breakpoint ,选择java.util.zip.ZipException
类,然后重新启动Tomcat实例。
当JVM在ZipException
断点处挂起时,您必须转到
堆栈跟踪中为JarFile.getManifestFromReference()
,并检查属性name
以查看文件名。
之后,您应该从文件系统中删除该文件,然后右键单击您的项目,选择Maven,更新项目,选中强制更新快照/版本。
答案 2 :(得分:66)
您需要检查哪个罐子有问题。它必须被破坏。删除该jar并再次运行mvn spring-boot:run
命令。可能更多的是一个jar已经损坏所以每次你需要运行该命令来删除该jar。在我的情况下,mysql,jackson,aspect jars已损坏mvn spring-boot:run
命令3次,我发现了这一点并从.m2
文件夹中删除了jar。现在问题已经解决了。
答案 3 :(得分:36)
从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)
答案 4 :(得分:9)
答案 5 :(得分:5)
我的解决方案是使用mvn
运行-X
:
$ 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/
答案 6 :(得分:2)
在pom文件中看起来像maven编译器的配置问题。默认版本java源和目标是1.5,甚至使用JDK有更高版本。
要修复,请添加具有更高java版本的maven编译器插件配置部分,例如:
<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>
有关详情,请查看以下链接:
答案 7 :(得分:1)
我正在面对这个问题,我的耳朵是我的本地weblogic实例。清理本地存储库并再次构建耳朵为我解决了这个问题。
答案 8 :(得分:1)
我们可以使用至少两个选项强制在maven中进行校验和验证:
1。将--strict-checksums
添加到我们的maven命令中。
2。将以下配置添加到我们的maven设置文件中:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<!--...-->
<profiles>
<profile>
<!--...-->
<repositories>
<repository>
<id>codehausSnapshots</id>
<name>Codehaus Snapshots</name>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>
<!--...-->
</url>
</repository>
</repositories>
<pluginRepositories>
<!--...-->
</pluginRepositories>
<!--...-->
</profile>
</profiles>
<!--...-->
</settings>
此职位的更多详细信息:https://dzone.com/articles/maven-artifact-checksums-what
答案 9 :(得分:1)
这个答案不是针对DevOps /系统管理员,而是针对那些使用IDE的人,例如eclipse并面临invalid LOC header (bad signature)
问题。
您可以强制更新maven依赖项,如下所示:
答案 10 :(得分:1)
除了删除.m2 / repository,从服务器删除应用程序,运行服务器(没有应用程序),停止它并再次添加应用程序。现在它应该工作。出于某种原因,只是从界面清理服务器文件夹不会产生同样的效果。
答案 11 :(得分:0)
这可能是由于很多原因:
1:尝试更改Web.XML版本
2:您尝试使用的Jar可能已损坏。例如:为Maven中的Jar使用不同的版本
答案 12 :(得分:0)
主要是由maven引起的。如果您使用的是IDEA,请尝试这些 以下步骤:
1.使用IDEA执行“maven clean”,然后你会看到
[INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for com.hisen:BookSystem_V0:war:1.0-SNAPSHOT [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 116, column 15 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
更换错误的jar
2.使用IDEA执行“maven compile”,然后你会看到
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Failure executing javac, but could not parse the error:
错误: 读取/Users/qinkai/.m2/repository/ch/qos/logback/logback-classic/1.1.1/logback-classic-1.1.1.jar时出错; invalid LOC header (bad signature)
错误: 读取/Users/qinkai/.m2/repository/ch/qos/logback/logback-core/1.1.1/logback-core-1.1.1.jar时出错; invalid LOC header (bad signature)
2 个错误
解决错误的jar
然后问题就解决了。答案 13 :(得分:0)
使用选项“-e -X”构建项目以找出损坏的jar&amp;从本地存储库中删除jar。
答案 14 :(得分:0)
“无效的LOC处理程序(错误签名)”
这可能是由于Maven下载的jar损坏。快速修复,我建议备份 .m2 / repository 目录并删除 .m2 / repository 目录,然后执行重建或Maven更新。
答案 15 :(得分:0)
这是一个用Java编写的小型检测器,只需复制并运行:)
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
public class JarValidator {
public static void main(String[] args) throws IOException {
Path repositoryPath = Paths.get("C:\\Users\\goxr3plus\\.m2");
// Check if the main Repository Exists
if (Files.exists(repositoryPath)) {
// Create a class instance
JarValidator jv = new JarValidator();
List<String> jarReport = new ArrayList<>();
jarReport.add("Repository to process: " + repositoryPath.toString());
// Get all the directory files
List<Path> jarFiles = jv.getFiles(repositoryPath, ".jar");
jarReport.add("Number of jars to process: " + jarFiles.size());
jarReport.addAll(jv.openJars(jarFiles, true));
// Print the report
jarReport.stream().forEach(System.out::println);
} else {
System.out.println("Repository path " + repositoryPath + " does not exist.");
}
}
/**
* Get all the files from the given directory matching the specified extension
*
* @param filePath Absolute File Path
* @param fileExtension File extension
* @return A list of all the files contained in the directory
* @throws IOException
*/
private List<Path> getFiles(Path filePath, String fileExtension) throws IOException {
return Files.walk(filePath).filter(p -> p.toString().endsWith(fileExtension)).collect(Collectors.toList());
}
/**
* Try to open all the jar files
*
* @param jarFiles
* @return A List of Messages for Corrupted Jars
*/
private List<String> openJars(List<Path> jarFiles, boolean showOkayJars) {
int[] badJars = { 0 };
List<String> messages = new ArrayList<>();
// For Each Jar
jarFiles.forEach(path -> {
try (JarFile file = new JarFile(path.toFile())) {
if (showOkayJars)
messages.add("OK : " + path.toString());
} catch (IOException ex) {
messages.add(path.toAbsolutePath() + " threw exception: " + ex.toString());
badJars[0]++;
}
});
messages.add("Total bad jars = " + badJars[0]);
return messages;
}
}
输出
Repository to process: C:\Users\goxr3plus\.m2
Number of jars to process: 4920
C:\Users\goxr3plus\.m2\repository\bouncycastle\isoparser-1.1.18.jar threw exception: java.util.zip.ZipException: zip END header not found
Total bad jars = 1
BUILD SUCCESSFUL (total time: 2 seconds)
答案 16 :(得分:0)
大部分时间都是因为zars损坏而发生的 更新pom.xml文件中的maven中央存储库url解决了我的问题 你可以使用这个网址 https://repo.maven.apache.org/maven2/ 但在此之前删除.m2目录中的文件 希望这有帮助
答案 17 :(得分:0)
也许与这个问题的最初原因无关,但是对于那些将面临gradle和本地模块依赖性的人
dependencies {
checkstyle project(":module")
}
如果模块不包含组和版本,则可能会发生此错误,因此只需在module/build.gradle
中指定
plugins {
id 'java-library'
}
group = "com.example"
version = "master-SNAPSHOT"
答案 18 :(得分:0)
如果您使用的是CentOS linux系统,则Maven本地存储库将为:
/root/.m2/repository/
您可以删除.m2并在开发工具中构建您的maven项目将解决此问题。