spring 构建期间的弹簧错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13044628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 05:27:28  来源:igfitidea点击:

spring error during build

springmavenspring-mvc

提问by Swift Sharp

I have to make small website using spring. so i chose spring template projectthen new spring mvc projectwhatever i try there is an error that occurred

我必须使用spring. 所以我选择spring template project然后new spring mvc project不管我尝试有发生错误

Errors occurred during the build.
Errors running builder 'Maven Project Builder' on project 'mTime'.Errors occurred during the build.
Errors running builder 'Maven Project Builder' on project 'mTime'.
Could not calculate build plan: Failed to parse plugin descriptor for org.apache.maven.plugins:maven-war-plugin:2.1.1 (C:\Users\User01\.m2\repository\org\apache\maven\plugins\maven-war-plugin.1.1\maven-war-plugin-2.1.1.jar): invalid LOC header (bad signature)
Failed to parse plugin descriptor for org.apache.maven.plugins:maven-war-plugin:2.1.1 (C:\Users\User01\.m2\repository\org\apache\maven\plugins\maven-war-plugin.1.1\maven-war-plugin-2.1.1.jar): invalid LOC header (bad signature)
Could not calculate build plan: Failed to parse plugin descriptor for org.apache.maven.plugins:maven-war-plugin:2.1.1 (C:\Users\User01\.m2\repository\org\apache\maven\plugins\maven-war-plugin.1.1\maven-war-plugin-2.1.1.jar): invalid LOC header (bad signature)
Failed to parse plugin descriptor for org.apache.maven.plugins:maven-war-plugin:2.1.1 (C:\Users\User01\.m2\repository\org\apache\maven\plugins\maven-war-plugin.1.1\maven-war-plugin-2.1.1.jar): invalid LOC header (bad signature)

i know that mavenis included in spring framework, and when i check the directory, the jars are there.

我知道它maven包含在 中spring framework,当我检查目录时,罐子就在那里。

How can I solve this error?

我该如何解决这个错误?

回答by Tomasz Nurkiewicz

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:

这表明某些二进制文件被破坏,很可能是依赖项之一。如果您的 Internet 连接速度很快,只需删除整个 maven 存储库并让 maven 重新下载所有依赖项:

rm -rf ~/.m2/repository/*

See also

也可以看看

回答by Ken Chan

From my experience , invalid LOC header (bad signature)is most probably due to the downloaded .jar file is corrupt.

根据我的经验,invalid LOC header (bad signature)很可能是由于下载的 .jar 文件已损坏。

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 -Uto download the dependencies again.

如果您的 Internet 连接速度较慢,您可以尝试根据错误消息的提示(即C:\Users\User01\.m2\repository\org\apache\maven\plugins\maven-war-plugin\2.1.1\)删除包含有问题的 jar 的文件夹,而不是删除整个 Maven 存储库。然后使用mvn clean install -U再次下载依赖项。

回答by Ketul patel

It Throw Because your .jar is Invalid Or Corrupted.

它抛出是因为您的 .jar 无效或已损坏。

Follow the Steps:

按照步骤:

Note : .m2 Folder is Hidden by Default. UnHide the Folder.

注意:.m2 文件夹默认是隐藏的。取消隐藏文件夹。

Step 1:Delete all the Content in .m2/repository Folder.

步骤 1:删除 .m2/repository 文件夹中的所有内容。

Step 2:Restart Your Eclipse.

第 2 步:重新启动 Eclipse。

Step 3:Maven->Update Project .Checked- Force Update of Snapshots/Releases.

第 3 步:Maven->Update Project .Checked-强制更新快照/发布。

Step 4:Run as Maven Clean.

第 4 步:作为 Maven Clean 运行。

Step 5:Run as Maven Install.

第 5 步:作为 Maven 安装运行。

Step 6: Clean Project.

第 6 步:清理项目。

Step 7 : Run Your Project.

第 7 步:运行您的项目。

I Hope you Find your Solution Here..

我希望你在这里找到你的解决方案..

Thanks..

谢谢..

回答by Wolfgang Fahl

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.

对我来说,多次运行以下脚本是有效的。它在 mvn 结果中查找 CEN 和 LOC 标题行问题,并要求一一删除 jar。经过几次删除和重新运行后,事情应该会再次运行。我不敢完全自动化。

#!/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

回答by Rian

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

运行 maven 时添加调试输出。它会告诉你哪个罐子坏了。只删除那个。

回答by BenHT

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.

在 Windows 上启动 Tomcat 时出现此错误或无法运行 Wolfgang 的脚本时,找到罪魁祸首的另一种解决方案是将 catalina.jar 中的 JarResourceSet.class 替换为具有额外调试功能的版本。

Ie google for the source code for your version of Tomcat and adapt the initInternal() method :

即谷歌为您的 Tomcat 版本的源代码和调整 initInternal() 方法:

    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 :

要构建,您的类路径应指向您的 Tomcat lib 目录,例如:

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

然后使用 7zip 或类似程序将其插入到相应目录下的 catalina.jar 中并运行 Tomcat。我很惊讶它第一次奏效,但确实如此。(然后你只需要在你的 .m2 存储库中找到有问题的 jar 文件并删除和重建等。)

回答by egore911

If you don't want to completely remove your local maven repository, use the following to find the broken artifacts and remove them:

如果您不想完全删除本地 Maven 存储库,请使用以下命令查找损坏的工件并将其删除:

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

回答by Jithin U. Ahmed

Help -> Install New Softwares

From there install the bundle with Web developments, XML, CSS, Java EE ... And after that if this built problem still continue, please use the command

从那里安装带有 Web 开发、XML、CSS、Java EE 的包……之后如果这个构建的问题仍然存在,请使用命令

rm -rf ~/.m2/repository/*

回答by Karthik CP

Try this :

尝试这个 :

find ~/.m2  -name "*.lastUpdated" -exec grep -q "Could not transfer" {} \; -print -exec rm {} \;