maven找不到课

我inheritance了一个巨大的maven java项目,无法进行编译。

mvn compile 

它告诉我它找不到一个类,即使它在当地的回购中也是如此。

 Failed to execute goal org.codehaus.enunciate:maven-enunciate-plugin:1.25:assemble (default) on project VCWH_Core_QueryService: Execution default of goal org.codehaus.enunciate:maven-enunciate-plugin:1.25:assemble failed: A required class was missing while executing org.codehaus.enunciate:maven-enunciate-plugin:1.25:assemble: com/sun/mirror/apt/AnnotationProcessorFactory 

这是pom.xml片段,告诉它在哪里看:

   com.sun tools 1.7  

当然,tools-1.7.jar和tools-1.7.pom位于本地仓库中

\.m2\repository\com\sun\tools\1.7

如果我用jar tf tools-1.7.jar查看jar tf tools-1.7.jar内部,我可以看到课程

com/sun/mirror/apt/AnnotationProcessorFactory.class

我还在我的本地仓库中清除了sun文件夹,并在NetBeans中执行了“清理和构建”,并观看了sun文件夹返回到我的本地仓库,所以我知道远程仓库的连接性很好。

为什么不能找到它?

与您用于依赖项的坐标相比,jar文件位于错误的文件夹中。 Maven不会看你的位置。 正确的路径是.m2 / repository / com / sun / mirror / apt / apt-mirror-api / 0.1 / apt-mirror-api-0.1.jar。

您创建的本地存储库无效。 我建议改为使用像Nexus这样的存储库管理器并将jar文件上传到那里,然后让Maven从那里下载。 通过这种方式,您可以获得创建的pom文件,并且与您使用的GAV坐标相比,结构将自动更正。

尝试mvn clean compile -Umvn clean install -U

需要将其添加到maven-enunciate-plugin:

    com.sun tools 1.7 system C:\Program Files\Java\jdk1.7.0_79\lib\tools.jar true   

现在它看起来像这样:

  org.codehaus.enunciate maven-enunciate-plugin 1.25  ${basedir}/src/main/webapp/WEB-INF/enunciate.xml false false false    com.sun tools 1.7 system C:\Program Files\Java\jdk1.7.0_79\lib\tools.jar true      assemble     

但是,现在出现了一个新错误:

 Failed to execute goal org.codehaus.enunciate:maven-enunciate-plugin:1.25:assemble (default) on project VCWH_Core_QueryService: Problem assembling the enunciate app. com.sun.tools.apt.mirror.type.ClassTypeImpl cannot be cast to com.sun.mirror.type.AnnotationType -> [Help 1] 

有谁知道如何解决这个问题?

去你的m2 repository.delete所有的jar子。

mvn clean install

如果你正在使用eclipse做一个project cleanright click project->maven->update project

首先,仔细检查文件中是否有正确的Maven坐标(groupId,artifactId和version)。 找错别字。

这可能是由腐败的本地Maven回购引起的。 您可以使用这些步骤解决它。

选项1:

  1. 在项目中,右键单击:Maven> Update Project

  2. 在对话框中,选中复选框:强制更新快照/版本

  3. 单击确定

Maven将进行重建。

如果这不能解决您的问题,请转到选项2

选项2:

  1. 删除您当地的Maven仓库,计算机上的.m2目录

在MS Windows上


C:\ Documents and Settings \ .m2 c:\ Users \ .m2

在Mac / Linux上

〜/ .m2目录

请注意,在您的操作系统上,您可能需要配置操作系统以显示隐藏文件。

  1. 删除.m2目录后,重新启动Eclipse

  2. 在项目中,右键单击:Maven> Update Project

这将解决您的问题。