When deploying a Maven project, java.util.zip.ZipException is thrown: invalid LOC header (invalid signature)

I get the following exception when I run mvn install . I even deleted the local repository and started again, getting the same exception.

[ERROR] The target org.apache.maven.plugins: maven-shade-plugin: 2.1: shade (by default) in the project cores package failed: error creating shaded jar: invalid LOC header (invalid signature) → [Help 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> 

Mistake:

 [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 
+151
java-ee jar maven maven-3 maven-plugin deployment maven-shade-plugin
Aug 19 '15 at 9:00
source share
17 answers

You should check which can causes problems. It must be damaged. Remove this jar and run mvn spring-boot:run again. Maybe more than one jar is damaged, so every time you need to run this command to remove this jar. In my case, mysql, jackson, aspect jars were corrupted by the mvn spring-boot:run command 3 times, and I found out and deleted jars from the .m2 folder. Now the problem is resolved.

+70
Nov 16 '17 at 3:14
source share

The JAR file may be corrupted. Try deleting the contents of the following folder:

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

Then right click on your project, select Maven, Update Project, check for forced snapshot / release updates.

+204
Aug 09 '16 at 16:27
source share

The main problem is damaged banks.

To find the damaged file, you need to add the Java Exception breakpoint in the Eclipse breakpoint view or your preferred IDE, select the java.util.zip.ZipException class and restart the Tomcat instance.

When the JVM pauses at a ZipException breakpoint, you should go to JarFile.getManifestFromReference() in the stack trace and check the name attribute to see the file name.

After that, you should delete the file from the file system, and then right-click your project, select Maven, Update Project, check Force Update snapshots / releases.

+107
Jan 28 '17 at 21:06 on
source share

From gsitgithub / find-currupt-jars.txt, the following command lists all corrupted jar files in the repository:

 find /home/me/.m2/repository/ -name "*jar" | xargs -L 1 zip -T | grep error | grep invalid 

You can delete corrupted jar files and recompile the project.

Output Example:

 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) 
+39
Jul 03 '17 at 17:26
source share

I would like to give my practice.

Use your preferred IDE, like eclipse here:

  1. Find a suitable place on the exception stack
  2. Set conditional breakpoint
  3. Debug it
  4. It will print a damaged jar until exception

enter image description here

+9
Aug 17 '17 at 11:27
source share

The solution for me was to start mvn with -X :

 $ mvn package -X 

Then look back at the exit until you see the error, and then continue moving until you see the last jar file that mvn tried to process:

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

Look at the last jar before it goes down, and delete it from the local repository, i.e.

 $ rm -rf /Users/snowch/.m2/repository/org/eclipse/jetty/jetty-server/9.2.15.v20160210/ 
+5
04 Oct '17 at 13:36 on
source share

There seems to be a configuration problem for the maven compiler in your pom file. The java version of the source version and the target version version 1.5, even the JDK used, has a higher version.

To fix, add the maven plugin configuration section for the compiler with a higher version of java, for 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 information, check out these links:

maven compiler

bug report

+2
Mar 25 '17 at 11:21
source share

This answer is not for DevOps / system administrators, but for those using an IDE, such as eclipse, and encounters an invalid LOC header (bad signature) problem.

You can force update maven dependencies as follows:

enter image description here

enter image description here

+1
Apr 22 '18 at 4:49
source share

Here is a small detector written in Java, just copy and run :)

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

Exit

 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) 
+1
11 Oct '18 at 8:31
source share

We can force a checksum check in maven with at least two options:

1. Adding --strict-checksums to our maven team.

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> 

See more in this post: https://dzone.com/articles/maven-artifact-checksums-what

+1
Oct. 16 '18 at 18:20
source share

in most cases this is due to corrupted zars updating the central maven repository in the pom.xml file solved my problem you can use this url https://repo.maven.apache.org/maven2/ but before that delete the files in the directory .m2 hope this helps

0
Sep 05 '17 at 6:15
source share

Create a project with the option "-e -X" to find out the damaged jar and remove the jar from the local repository.

0
Sep 11 '17 at 10:20
source share

I ran into this problem when deploying my ear to my local network. Cleaning my local storage and ear assembly again solved the problem for me.

0
Dec 19 '17 at 10:31 on
source share

This may be due to many reasons:

1. Try changing the version of Web.XML

2: The jar you are trying to use may be damaged. For example, use a different version for the jar from Maven.

0
Feb 03 '18 at 19:17
source share

Besides uninstalling .m2 / repository, uninstall the application from the server, start the server (without applications), stop it and add the application again. This should work now. For some reason, simply clearing the server folders from the interface does not have the same effect.

0
Mar 20 '18 at 20:20
source share

This is mainly caused by maven. If you are using IDEA, try the following steps:

1. use IDEA to do "maven clean", then you will see

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

replace the wrong jar

2. use IDEA to execute the "maven compile", then you will see

 [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 个错误 

solve the wrong jar

then the problem will be solved.

0
Apr 21 '18 at 10:10
source share

"Invalid LOC handler (invalid signature)"
This is probably due to damaged banks that were downloaded by Maven. A quick fix, I recommend that you back up the .m2 / repository directory and delete the .m2 / repository directory , and then perform a restore or Maven-Update.

0
Jul 14 '18 at 18:18
source share



All Articles