I have to make small website using spring
. so i chose spring template project
then new spring mvc project
whatever i try there
for me running the following script multiple times worked. It looks for CEN and LOC header line issues in the mvn result and asks for deleting the jars one by one. After a few deletions and reruns things should be working again. I didn't dare to fully automate.
#!/bin/sh
# fix issues like:
#[ERROR] error: error reading /Users/wf/.m2/repository/org/docx4j/xhtmlrenderer/1.0.0/xhtmlrenderer-1.0.0.jar; invalid LOC header (bad signature)
# WF 2013-10-27
mvnlog=/tmp/mvnlog$$
mvnproblem=/tmp/mvnproblem$$
mvn install | tee $mvnlog
grep "invalid ... header" $mvnlog > $mvnproblem
for culprit in `cat $mvnproblem | cut -d" " -f5 | cut -d ";" -f1`
do
echo "fix mvn LOC header issue with $culprit? yes/no/abort"
read answer
case $answer in
y*|Y*) rm $culprit;;
n*|N*) ;;
*) exit 1;
esac
done
rm -f $mvnproblem
rm -f $mvnlog
The relevant part of the error message is:
invalid LOC header (bad signature)
which suggests some binary file being broken, most likely one of the dependencies. If you have a fast Internet connection, just delete your whole maven repository and let maven redownload all the dependencies:
rm -rf ~/.m2/repository/*
From my experience , invalid LOC header (bad signature)
is most probably due to the downloaded .jar file is corrupt.
If you have a slow internet connection , instead of deleting the whole Maven repository , you can try to delete the folder containing the problematic jar according to the hints of the errors message (i.e C:\Users\User01\.m2\repository\org\apache\maven\plugins\maven-war-plugin\2.1.1\
) . Then use mvn clean install -U
to download the dependencies again.
Another solution for finding the culprit when getting this error starting Tomcat on Windows or when you can't run Wolfgang's script is to replace JarResourceSet.class in catalina.jar with a version that has extra debugging.
Ie google for the source code for your version of Tomcat and adapt the initInternal() method :
String processingJar = "";
try (JarFile jarFile = new JarFile(getBase())) {
processingJar = jarFile.getName();
...
} catch (IOException ioe) {
System.out.println("Failed with " + processingJar);
throw new IllegalArgumentException(ioe);
}
To build, your classpath should point to your Tomcat lib directory eg :
javac -cp C:\apache-tomcat-X.Y.Z\lib\* JarResourceSet.java
Then use 7zip or similar program to insert it into catalina.jar in the appropriate directory and run Tomcat. I was astonished that it worked first time but it did. (Then you just need to find where in your .m2 repository the offending jar file is and delete and rebuild etc.)
If you don't want to completely remove your local maven repository, use the following to find the broken artifacts and remove them:
public static void main(String[] args) throws IOException {
findBrokenZip(Paths.get(System.getProperty("user.home") + "/.m2/repository"));
}
static void findBrokenZip(Path path) throws IOException {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
for (Path entry : stream) {
if (Files.isDirectory(entry)) {
findBrokenZip(entry);
} else {
if (entry.getFileName().toString().endsWith(".jar")) {
try (JarFile zipFile = new JarFile(entry.toFile())) {
zipFile.getManifest();
} catch (ZipException e) {
Files.delete(entry);
}
}
}
}
}
}
add debug output when running maven. It will show you which jar is broken. Delete just that one.