Java 无效的 LOC 标头(签名错误)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50675511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Invalid LOC header(bad signature)
提问by Ayman Patel
I am getting this error during my Maven build.
我在 Maven 构建期间收到此错误。
Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.4.3:shade (default) on project dl4j-examples: Error creating shaded jar: invalid LOC header (bad signature) -> [Help 1] [ERROR]
无法在项目 dl4j-examples 上执行目标 org.apache.maven.plugins:maven-shade-plugin:2.4.3:shade (default): Error creation shaded jar: invalid LOC header (bad signature) -> [Help 1] [错误]
This is my pom.xml file.
这是我的 pom.xml 文件。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>${shadedClassifier}</shadedClassifierName>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>org/datanucleus/**</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
I have tried to delete the jar file multiple times that does not seem to work.
我多次尝试删除似乎不起作用的 jar 文件。
回答by amit singh tomar
I also faced same issue, Ben is correct, it's the case of corrupt jar file. Just go to .m2 repo folder and delete it from there and again build it (mvn clean install). It would resolve the issue.
我也遇到了同样的问题,Ben 是对的,就是 jar 文件损坏的情况。只需转到 .m2 repo 文件夹并从那里删除它并再次构建它(mvn clean install)。它会解决这个问题。
回答by Tiago Mazzucco
I've been facing this issue for a long time
我已经面临这个问题很长时间了
So I decided to automate the identification and the removal of corrupt jars
所以我决定自动识别和移除损坏的罐子
this is the util class I created for this purpose:
这是我为此目的创建的 util 类:
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.jar.JarFile;
public class MavenFix {
public static void main(String[] args) throws IOException {
Files.walk(Paths.get("C:/data/.m2/repository"))
.filter(file -> file.toString().endsWith("jar"))
.forEach(path -> {
try {
System.out.print(".");
new JarFile(path.toString(), true).getManifest();
} catch (Exception e) {
System.out.println();
System.out.println(path + " - " + e.getMessage());
try {
cleanAndDeleteDirectory(path.getParent().toFile());
} catch (IOException e1) {
System.err.println(e1.getMessage());
}
}
});
}
public static void cleanAndDeleteDirectory(File dir) throws IOException {
File[] files = dir.listFiles();
if (files != null && files.length > 0) {
for (File aFile : files) {
Files.delete(aFile.toPath());
}
}
Files.delete(dir.toPath());
}
}