【问题标题】:mvn COMPILATION ERROR : error reading jar error in opening zip filemvn 编译错误:打开 zip 文件时读取 jar 错误
【发布时间】:2016-12-28 15:08:02
【问题描述】:

我有一个具有这些属性的 x 模块:

模块名称:x-datamodel

这是 pom.xml 的一部分

<groupId>com.x.datamodel</groupId>
<artifactId>x</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

我已使用此命令行将项目安装在本地存储库中:

mvn install:install-file -Dfile=/Users/me/Documents/Projects/x-datamodel/target/classes/x-datamodel.jar -DgroupId=com.x.datamodel -DgeneratePom=true -DlocalRepositoryPath=/Users/me/Documents/Projects/me-repository  -DcreateChecksum=true -DartifactId=x -Dversion={1.0} -Dpackaging=jar

并将项目添加到 bitbucket 中。

我尝试将模块 x 集成到另一个项目 y 中。

这里是 y 的 pom.xml 的一部分

<dependency>
    <groupId>com.x.datamodel</groupId>
    <artifactId>x</artifactId>
    <version>${x.version}</version>
</dependency>

<repositories>
    <repository>
        <id>me-repository</id>
        <url>https://bitbucket.org/me/me-repository/src/master</url>
    </repository>
</repositories>

我可以在项目 y 中导入模块 x 的一些类,但是当我构建 y 项目时出现此错误:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] error reading /Users/me/.m2/repository/com/x/datamodel/x/1.0/x-1.0.jar; error in opening zip file
[ERROR] error reading /Users/me/.m2/repository/com/x/datamodel/x/1.0/x-1.0.jar; error in opening zip file
[ERROR] /Users/me/Documents/Projects/y/src/main/java/com/y/server/serviceImpl/UserServiceImpl.java:[3,32] package com.x.datamodel.model does not exist
[ERROR] /Users/me/Documents/Projects/y/src/main/java/com/y/server/serviceImpl/UserServiceImpl.java:[18,12] cannot find symbol
  symbol:   class User
  location: class com.y.server.serviceImpl.UserServiceImpl
[ERROR] /Users/me/Documents/Projects/y/src/main/java/com/y/server/security/CustomUserDetailsService.java:[3,32] package com.x.datamodel.model does not exist
[INFO] 16 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:56 min
[INFO] Finished at: 2016-12-28T15:51:05+01:00
[INFO] Final Memory: 29M/209M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project y: Compilation failure: Compilation failure:
[ERROR] error reading /Users/me/.m2/repository/com/x/datamodel/x/1.0/x-1.0.jar; error in opening zip file
[ERROR] error reading /Users/me/.m2/repository/com/x/datamodel/x/1.0/x-1.0.jar; error in opening zip file
[ERROR] /Users/me/Documents/Projects/y/src/main/java/com/y/server/serviceImpl/UserServiceImpl.java:[3,32] package com.x.datamodel.model does not exist
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

安装存储库后,我将库放入此路径:

.m2/repository/com/x/datamodel/x/1.0/x-1.0.jar

为什么不:

.m2/repository/com/x-datamodel/x/1.0/x-1.0.jar

【问题讨论】:

  • -Dversion={1.0} 应该是-Dversion=1.0 吗?
  • 没有解决问题。同样的问题
  • 指定的网址是否包含jar?您是否从您尝试访问的地方部署到远程?
  • 一个类似的线程 - *.com/questions/14013644/…
  • 答案是 groupId com.x.datamodel 确保 com/x/model/ 作为文件夹结构,后跟 artifactId-version.jar 文件名

标签: java maven module maven-3


【解决方案1】:

我倾向于认为文件已损坏。尝试删除它并重新下载。

【讨论】:

  • 我做到了。我删除了所有 util .m2/repository/ 并运行 mvn clean install。但同样的问题
  • 如果您有 jar 文件的校验和,请尝试将其与下载文件的校验和进行比较。此外,您可以尝试jar tvf 列出 jar 文件的内容,作为健全性检查。祝你好运!