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.
<
Here is an 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;
}
}
Output
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)
The solution for me was to run mvn
with -X
:
$ mvn package -X
Then look backwards through the output until you see the failure and then keep going 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 failed and remove that from the local repository, i.e.
$ rm -rf /Users/snowch/.m2/repository/org/eclipse/jetty/jetty-server/9.2.15.v20160210/
I was facing this issue while deploying my ear to my local weblogic instance. Clearing the local repository and building the ear again resolved the issue for me.
If you are using CentOS linux system the Maven local repositary will be:
/root/.m2/repository/
You can remove .m2 and build your maven project in dev tool will fix the issue.
Beyond removing .m2/repository, remove application from server, run server (without applications), stop it and add application again. Now it is supposed to work. For some reason just cleaning up server folders from interface doesn't have the same effect.
The mainly problem are corrupted jars.
To find the corrupted one, you need to add a Java Exception Breakpoint in the Breakpoints View of Eclipse, or your preferred IDE, select the java.util.zip.ZipException
class, and restart Tomcat instance.
When the JVM suspends at ZipException
breakpoint you must go to
JarFile.getManifestFromReference()
in the stack trace, and check attribute name
to see the filename.
After that, you should delete the file from file system and then right click your project, select Maven, Update Project, check on Force Update of Snapshots/Releases.