Java 错误:无法读取所需库的存档或不是有效的 ZIP 文件。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21093129/
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-08-13 06:31:30  来源:igfitidea点击:

Error: Archive for required library cannot be read or is not a valid ZIP file.

javaeclipsejararchivebuildpath

提问by

I am having trouble setting up the build path of my java project. I am currently in a Co-Op IT position so I am somewhat new to all this. My background is mostly in C++ and I am learning java on the fly. I am also somewhat new to Eclipse (Kepler service release 1).

我在设置 java 项目的构建路径时遇到问题。我目前在 Co-Op IT 职位,所以我对这一切都有些陌生。我的背景主要是 C++,我正在即时学习 Java。我对 Eclipse(开普勒服务第 1 版)也有些陌生。

I am working on a bug on an existing program and need to get the program to build so I can work on it. When I add all of the external .jar files that I know for a fact are the right ones, I am getting this error on two of them :

我正在处理现有程序的错误,需要构建程序以便我可以处理它。当我添加所有我知道的外部 .jar 文件是正确的文件时,我在其中两个文件上收到此错误:

"Archive for required library: '(location of file)' cannot be read or is not a valid ZIP file"

“所需库的存档:'(文件位置)'无法读取或不是有效的 ZIP 文件”

Two of the other full time guys on my team have gotten the program to run with those exact same .jar files, one running Eclipse Indigo and the other running the same Kepler version as myself. I also was able to open the two .jar files manually and everything appears to be there. After every trial trying to fix this, I have refreshed, cleaned and restarted eclipse. The two other full time guys said they have never seen this error. I would like to get some insight on this from anyone who has any similar experiences so that I don't have to use up much more of their time.

我团队中的另外两个全职人员已经让程序使用完全相同的 .jar 文件运行,一个运行 Eclipse Indigo,另一个运行与我相同的 Kepler 版本。我还能够手动打开两个 .jar 文件,一切似乎都在那里。在每次尝试解决此问题后,我都刷新、清理并重新启动了 eclipse。另外两个全职人员说他们从未见过这个错误。我想从任何有类似经历的人那里获得一些见解,这样我就不必占用他们更多的时间。

回答by AnhSirk Dasarp

I Had this issue, just fixed by deleting .jar files from Libs directory then copy->paste original Jars again. Then do a complete clean -> rebuild

我遇到了这个问题,只是通过从 Libs 目录中删除 .jar 文件然后再次复制->粘贴原始 Jars 来解决的。然后做一个完整的清理 - >重建

回答by Frank Fu

I got the same problem and found out the root cause is the JDK in my linux shell is set to 1.6, but in the eclipse, the JRE is 1.7.

我遇到了同样的问题,发现根本原因是我的 linux shell 中的 JDK 设置为 1.6,但在 eclipse 中,JRE 为 1.7。

回答by Basilevs

Using Eclipse without m2e features (Standard Edition) helped me.

使用没有 m2e 功能的 Eclipse(标准版)帮助了我。

Similar problem with Spring toolsuite

Spring工具包的类似问题

回答by Calixto

I had the same error here. What I did to resolve the problem was close and reopen the project.

我在这里遇到了同样的错误。我为解决问题所做的是关闭并重新打开项目。

回答by xbranko

Just came across this linkthat shows a way to get unblocked. In preferences dialog box go to

刚刚看到这个链接,它显示了一种解除封锁的方法。在首选项对话框中转到

Java->Compiler->Building

and change Incomplete build path to "Warning" (from default "Error") This can be done globally (for all projects), or on a project by project basis.

并将不完整的构建路径更改为“警告”(从默认的“错误”)这可以在全局(对于所有项目)或逐个项目的基础上完成。

回答by user1384205

Check the jar's file permissions/ownership. I had the same issue on eclipse installed on Linux and fixed it by setting the file permissions right.

检查 jar 的文件权限/所有权。我在 Linux 上安装的 eclipse 上遇到了同样的问题,并通过正确设置文件权限来修复它。

回答by Akshay Vijay Jain

I got this problem, took help from following link solutionwhich basically says to 1. delete the corresponding maven download folder 2. maven>update project in eclipse

我遇到了这个问题,从以下链接解决方案中获得帮助, 该解决方案基本上是 1. 删除相应的 maven 下载文件夹 2. maven>update project in eclipse

In my case I deleted hibernate folder, since i was getting error related to hibernate-validator.jar

就我而言,我删除了 hibernate 文件夹,因为我收到了与 hibernate-validator.jar 相关的错误

回答by Debasish Ghosh

In my case ..worked after removing this from spirngrest-servlet.xml file.

在我的情况下..从 spirngrest-servlet.xml 文件中删除它后工作。

    <prop key="net.sf.ehcache.configurationResourceName">/Sysehcache.xml</prop>

I think it had to do with default location of maven repository of jar files. Been at it for 3 days. finally solved it.Hope it helps anyone.Just look for similar think in your spirngrest-servlet.xml file. Good luck.

我认为这与 jar 文件的 maven 存储库的默认位置有关。坚持了3天。终于解决了。希望它可以帮助任何人。只需在您的 spirngrest-servlet.xml 文件中寻找类似的想法。祝你好运。

回答by Nandan Chaturvedi

I just tried the following and it worked:

我只是尝试了以下方法,它奏效了:

Close eclipse as there might be some files eclipse is accessing and you won't be able to delete.

关闭 eclipse,因为可能有一些 eclipse 正在访问的文件,您将无法删除。

Delete all the libraries installed in the maven repositories folder: ".m2/repository"

删除maven repositories文件夹中安装的所有库:“.m2/repository”

Open eclipse and update your project(Alt+F5).

打开 Eclipse 并更新您的项目(Alt+F5)。

What did we just do?: This is possible that the existing libraries in the local repository are erroneous and maven tries to open which it fails in. We have now deleted the already existing library and with the project update, Maven will download the library again which should resolve the issue.

我们刚刚做了什么?:这可能是本地存储库中的现有库是错误的,maven 尝试打开它失败了。我们现在已经删除了已经存在的库,并且随着项目更新,Maven 将再次下载该库,这应该可以解决问题。

回答by incognito nerd

i fixed this by just deleting everything inside of the /Users/username/.m2/repository folder. not the repository folder itself. and then running a mvn clean package in the project folder

我通过删除 /Users/username/.m2/repository 文件夹中的所有内容来解决此问题。不是存储库文件夹本身。然后在项目文件夹中运行一个 mvn clean 包