Deploying Maven project throws java.util.zip.ZipException: invalid LOC header (bad signature)

前端 未结 14 1890
予麋鹿
予麋鹿 2020-11-22 08:03

I am getting the below exception when I run my mvn install. I have even deleted the local repository and ran again getting same exception.

<
相关标签:
14条回答
  • 2020-11-22 08:26

    I'd like to give my give my practice.

    Use your preferred IDE, take eclipse for for example here:

    1. Find an appropriate location within the exception stack
    2. Set conditional breakpoint
    3. Debug it
    4. It will print the corrupted jar before exception

    0 讨论(0)
  • 2020-11-22 08:26

    Looks like problem of configuration for maven compiler in your pom file. Default version java source and target is 1.5, even used JDK has higher version.

    To fix, add maven compiler plugin configuration section with higher java version, example:

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

    For more info check these links:

    maven compiler

    bug report

    0 讨论(0)
  • 2020-11-22 08:28

    You need to check which jar is giving problem. It must be corrupted. Delete that jar and run mvn spring-boot:run command again. May be more that one jar has corrupted so every time you need to run that command to delete that jar. In my case mysql, jackson, aspect jars was corrupted mvn spring-boot:run command 3 times and I figure out this and deleted the jars from .m2 folder. Now the issue has resolved.

    0 讨论(0)
  • 2020-11-22 08:30

    This answer is not for DevOps/ system admin guys, but for them who are using IDE like eclipse and facing invalid LOC header (bad signature) issue.

    You can force update the maven dependencies, as follows:

    0 讨论(0)
  • 2020-11-22 08:30

    We can force the checksum validation in maven with at least two options:

    1.Adding the --strict-checksums to our maven command.

    2.Adding the following configuration to our maven settings file:

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

    More details in this post: https://dzone.com/articles/maven-artifact-checksums-what

    0 讨论(0)
  • 2020-11-22 08:31

    The jar file may be corrupt. Try removing the content of the following folder:

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

    Then right click your project, select Maven, Update Project, check on Force Update of Snapshots/Releases.

    0 讨论(0)
提交回复
热议问题