Java eclipse maven 错误:无法读取项目中所需库的存档或不是有效的 ZIP 文件

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

eclipse maven error: Archive for required library in project cannot be read or is not a valid ZIP file

javaeclipsespringhibernatemaven

提问by CodeMed

In an eclipse maven project using spring web mvc, I am getting the following error in the Markers tab:

在使用 spring web mvc 的 eclipse maven 项目中,我在“标记”选项卡中收到以下错误:

Archive for required library: 'D:/mypath/.m2/repository/javax/transaction/jta/1.0.1B/jta-1.0.1B.jar' in project 'DocumentManager' cannot be read or is not a valid ZIP file

I have checked, and the jar file is in fact present in the url indicated. I even copied a backup of the jar to overwrite the jar file in that location, but that did not get rid of the error either. I forced maven to update, which did not solve the problem. I also restarted eclipse to no effect.

我已经检查过,jar 文件实际上存在于指示的 url 中。我什至复制了 jar 的备份以覆盖该位置的 jar 文件,但这也没有消除错误。我强制maven更新,没有解决问题。我也重新启动 eclipse 没有效果。

At one point, jta-1.0.1B.jar had been jta-1.0.1B.jar.LatestUpdate, so I shortened the name to jta-1.0.1B.jar

有一次,jta-1.0.1B.jar 已经是 jta-1.0.1B.jar.LatestUpdate,所以我将名称缩短为 jta-1.0.1B.jar

In pom.xml, the location of the error message is line 2, which reads as follows:

在pom.xml中,错误信息的位置是第2行,内容如下:

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  

When I download jta-1.0.1B.jar manually from this url, the error in pom.xml goes away but is replaced with new errors in .java class files indicating that 5 methods of the Document class are not valid.

当我从这个 url手动下载 jta-1.0.1B.jar 时,pom.xml 中的错误消失了,但替换为 .java 类文件中的新错误,表明 Document 类的 5 个方法无效。

I read thisand this, but I am not using struts, I am already including 3.3.2.ga of hibernate, and I do not have a repository tag in pom.xml (which thissaid did not even solve the problem anyway), so I do not think this is a duplicate.

我阅读了thisthis,但我没有使用struts,我已经包含了3.3.2.ga的hibernate,而且我在pom.xml中没有存储库标签(说它甚至没有解决问题),所以我不认为这是重复的。

Can anyone suggest a way to fix this problem? If I need a repository tag, where do I put it? And what else do I change to accommodate its addition?

任何人都可以提出解决此问题的方法吗?如果我需要一个存储库标签,我应该把它放在哪里?我还需要更改什么以适应其添加?

For anyone who is curious, my pom.xml is included for reference as follows:

对于任何好奇的人,我的 pom.xml 被包含以供参考,如下所示:

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <description></description>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0.1</version>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <version>1.1.2</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.1.2</version>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>3.3.2.GA</version>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.10</version>
    </dependency>
    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>20030825.184428</version>
    </dependency>
    <dependency>
      <groupId>commons-pool</groupId>
      <artifactId>commons-pool</artifactId>
      <version>1.5.4</version>
    </dependency>
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.2.1</version>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>1.3</version>
    </dependency>
<!-- dependency to fix JSPServletException -->
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>jsp-api</artifactId>
        <version>6.0.32</version>
        <scope>provided</scope>               
    </dependency>
  </dependencies>
  <properties>
    <org.springframework.version>3.2.4.RELEASE</org.springframework.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <groupId>DocumentManager</groupId>
  <artifactId>DocumentManager</artifactId>
</project>  

回答by Aaron Digulla

To fix issues like that, let Maven download the files again:

要解决此类问题,请让 Maven 再次下载文件:

  1. Delete the folder D:/mypath/.m2/repository/javax/transaction/jta
  2. Run Maven with -Uso it tries broken downloads again.
  1. 删除文件夹 D:/mypath/.m2/repository/javax/transaction/jta
  2. 运行 Maven-U以便它再次尝试损坏的下载。

That should try to download the file again and clean up any "residue" in your local repository.

那应该尝试再次下载文件并清除本地存储库中的任何“残留物”。

If Eclipse still complains that the JAR file is corrupt:

如果 Eclipse 仍然抱怨 JAR 文件已损坏:

  1. Refresh your project (F5or from the context menu)
  2. Clean the project
  3. Try to open the JAR file. Maybe it's really corrupt.
  1. 刷新您的项目(F5或从上下文菜单)
  2. 清理项目
  3. 尝试打开 JAR 文件。也许它真的很腐败。

If the JAR file is corrupt, delete the folder again and run Maven once more. Note the URLs which Maven used to download the archive and contact the administrator of that site.

如果 JAR 文件已损坏,请再次删除该文件夹并再次运行 Maven。请注意 Maven 用于下载存档的 URL,并联系该站点的管理员。

回答by M. Deinum

The maven central repository doesn't contain a jar file for the given groupId/artifactId only a pom.xml.

maven 中央存储库不包含给定 groupId/artifactId 的 jar 文件,只有pom.xml

maven central results

Maven 中心结果

You are using Spring 3.2 so I suggest you simply upgrade hibernate to the most recent version (4.2.6.Final) which should have a reference to jta 1.1. Or simply include the 1.1 version in your pom which does have a jar in maven central.

您使用的是 Spring 3.2,所以我建议您只需将 hibernate 升级到最新版本(4.2.6.Final),该版本应该引用 jta 1.1。或者简单地在你的 pom 中包含 1.1 版本,它在 maven central 中有一个 jar。

回答by Munseok Koh

To fix this issue simply.

简单地解决这个问题。

  1. select all libraries in "Maven Dependencies" of related project.
  2. just do "Refresh" of mouse right button...
  1. 选择相关项目的“Maven Dependencies”中的所有库。
  2. 只需执行鼠标右键“刷新”...

The reason is cache info, so just refresh the information.

原因是缓存信息,所以只需刷新信息。

回答by user3638990

You should exclude JTA in your hibernate dependency.

您应该在您的休眠依赖项中排除 JTA。

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate</artifactId>
    <version>3.2.3.ga</version>
    <exclusions>
        <exclusion>
            <artifactId>javax.transaction</artifactId>
            <groupId>jta</groupId>
        </exclusion>
    </exclusions>
</dependency>

After that, add the jta dependency.

之后,添加 jta 依赖项。

<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>jta</artifactId>
    <version>1.1</version>
</dependency>

回答by Amit Kumar

The problem with me was fixed by going to Build Path-> Configure Build Path-> Libraries-> Remove the jta libwhich has small cross mark on it.

我的问题是通过转到上面Build Path-> Configure Build Path-> Libraries-> Remove the jta lib有小十字标记的地方来解决的。

I was able to successfully build my project but was getting this error even after project Refresh/Project Clean.

我能够成功构建我的项目,但即使在项目刷新/项目清理之后也出现此错误。

回答by Sachindeep Singh

You can manually go to the repository specified in the error console that is Archive for required library: '**D:/mypath/.m2/repository/javax/transaction/jta/1.0.1B/jta-1.0.1B.jar**' in project 'DocumentManager' cannot be read or is not a valid ZIP file

您可以手动转到错误控制台中指定的存储库 Archive for required library: '**D:/mypath/.m2/repository/javax/transaction/jta/1.0.1B/jta-1.0.1B.jar**' in project 'DocumentManager' cannot be read or is not a valid ZIP file

Delete the JAR mentioned

删除提到的 JAR

Go to eclipse, right click the project and select run as->maven-install. It will download the right jar file.

进入eclipse,右键项目,选择run as->maven-install。它将下载正确的 jar 文件。

回答by SRI RaMan

Tried with 1.5.5 Release jar and it worked for me

尝试使用 1.5.5 Release jar,它对我有用

<groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.5.RELEASE</version>

https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent/1.5.5.RELEASE

https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent/1.5.5.RELEASE