IT박스

Maven 프로젝트를 배포하면 java.util.zip.ZipException이 발생합니다. 잘못된 LOC 헤더 (잘못된 서명)

itboxs 2020. 6. 9. 22:20
반응형

Maven 프로젝트를 배포하면 java.util.zip.ZipException이 발생합니다. 잘못된 LOC 헤더 (잘못된 서명)


내을 실행할 때 아래 예외가 발생합니다 mvn install. 로컬 저장소를 삭제하고 동일한 예외가 다시 발생했습니다.

[오류] 프로젝트 코어에서 org.apache.maven.plugins : maven-shade-plugin : 2.1 : shade (기본값) 목표를 실행하지 못했습니다. ]

<?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

어떤 항아리에 문제가 있는지 확인해야합니다. 손상되어 있어야합니다. 해당 jar을 삭제하고 mvn spring-boot:run명령을 다시 실행 하십시오. 하나의 jar이 손상되었을 수 있으므로 해당 jar을 삭제하기 위해 해당 명령을 실행해야 할 때마다. 필자의 경우 mysql, jackson, aspect jars mvn spring-boot:run명령이 3 번 손상 되었으며이를 알아 내고 .m2폴더 에서 jar을 삭제했습니다 . 이제 문제가 해결되었습니다.


jar 파일이 손상되었을 수 있습니다. 다음 폴더의 내용을 제거하십시오.

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

그런 다음 프로젝트를 마우스 오른쪽 버튼으로 클릭하고 Maven, 프로젝트 업데이트를 선택하고 스냅 샷 / 릴리스 강제 업데이트를 확인하십시오.


주로 문제는 손상된 항아리입니다.

손상된 항목을 찾으려면 Eclipse의 중단 점보기 또는 선호하는 IDE에서 Java 예외 중단 점 을 추가 하고 java.util.zip.ZipException클래스를 선택한 후 Tomcat 인스턴스를 다시 시작해야합니다.

JVM이 중단 ZipException에서 일시 중단되면 JarFile.getManifestFromReference()스택 추적으로 이동하여 속성 name을 확인하여 파일 이름을 확인해야합니다 .

그런 다음 파일 시스템에서 파일을 삭제 한 다음 프로젝트를 마우스 오른쪽 단추로 클릭하고 Maven, 프로젝트 업데이트를 선택하고 스냅 샷 / 릴리스 강제 업데이트를 확인하십시오.


에서 gsitgithub / 찾아-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)

제 연습을하고 싶습니다.

선호하는 IDE를 사용하고 예를 들어 다음과 같이 일식을 취하십시오.

  1. 예외 스택 내에서 적절한 위치를 찾으십시오.
  2. 조건부 중단 점 설정
  3. 그것을 디버그
  4. 예외 전에 손상된 항아리를 인쇄합니다.

여기에 이미지 설명을 입력하십시오


나를위한 해결책은 다음 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)

실패하기 전에 마지막 항아리를보고 로컬 저장소에서 제거하십시오.

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

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>

자세한 정보는 다음 링크를 확인하십시오.

메이븐 컴파일러

버그 리포트


이 답변은 DevOps / 시스템 관리자가 아니라 일식 및 직면 invalid LOC header (bad signature)문제 와 같은 IDE를 사용하는 사람들을위한 것입니다 .

다음과 같이 maven 종속성을 강제로 업데이트 할 수 있습니다.

여기에 이미지 설명을 입력하십시오

여기에 이미지 설명을 입력하십시오


다음은 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)

적어도 두 가지 옵션을 사용하여 체크섬 유효성 검사를 maven으로 강제 실행할 수 있습니다.

1. --strict-checksumsmaven 명령 에을 추가하십시오 .

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


.m2 / repository를 제거하는 것 외에도 서버에서 응용 프로그램을 제거하고 (응용 프로그램없이) 서버를 실행 한 후 중지하고 다시 추가하십시오. 이제 작동합니다. 어떤 이유로 인터페이스에서 서버 폴더를 정리해도 동일한 효과가 없습니다.


귀를 로컬 weblogic 인스턴스에 배포하는 동안이 문제에 직면했습니다. 로컬 저장소를 지우고 귀를 다시 구축하면 문제가 해결되었습니다.

참고 : https://stackoverflow.com/questions/32090921/deploying-maven-project-throws-java-util-zip-zipexception-invalid-loc-header-b

반응형