LOC标头无效(签名错误)

时间:2018-06-04 07:36:47

标签: java maven pom.xml

我在Maven构建期间收到此错误。

无法执行目标org.apache.maven.plugins:maven-shade-plugin:2.4.3:项目上的阴影(默认)dl4j-examples:创建阴影jar时出错:无效的LOC标头(错误的签名) - > [帮助1] [错误]

这是我的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>

我试图多次删除jar文件似乎不起作用。

3 个答案:

答案 0 :(得分:5)

我也遇到同样的问题,本是正确的,这是jar文件损坏的情况。只需转到.m2 repo文件夹,然后从那里删除它,然后再次构建它(mvn clean install)。这样可以解决问题。

答案 1 :(得分:4)

我已经面对这个问题很长时间了

所以我决定自动化识别和清除损坏的罐子

这是我为此创建的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());
    }
}

答案 2 :(得分:2)

我遇到同样的问题,只需将其从.m2文件夹中删除,然后再次解决您的问题