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 jarReport = new ArrayList<>();
jarReport.add("Repository to process: " + repositoryPath.toString());
// Get all the directory files
List 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 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 openJars(List jarFiles, boolean showOkayJars) {
int[] badJars = { 0 };
List 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)