spring error during build

前端 未结 9 2091
独厮守ぢ
独厮守ぢ 2020-12-24 14:23

I have to make small website using spring. so i chose spring template project then new spring mvc project whatever i try there

相关标签:
9条回答
  • 2020-12-24 15:01

    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
    
    0 讨论(0)
  • 2020-12-24 15:05

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

    See also

    • some error while running spring mvc project
    • Maven:: Invalid CEN (bad signature) Invalid LOC (bad signature)
    0 讨论(0)
  • 2020-12-24 15:05

    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.

    0 讨论(0)
  • 2020-12-24 15:05

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

    0 讨论(0)
  • 2020-12-24 15:12

    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);
                        }
                    }
                }
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-24 15:13

    add debug output when running maven. It will show you which jar is broken. Delete just that one.

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