2015-11-14 113 views
4

我已经继承了一个巨大的maven java项目,无法编译它。maven找不到类

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的片段,告诉它到哪里寻找:

<dependency> 
    <groupId>com.sun</groupId> 
    <artifactId>tools</artifactId> 
    <version>1.7</version> 
</dependency> 

果然,工具-1.7.jar和工具,1.7.pom位于当地的回购

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

如果我看罐内与 jar tf tools-1.7.jar 我可以看到 类

com/sun/mirror/apt/AnnotationProcessorFactory.class

我也吹散了我的本地回购太阳文件夹,并做了“清理并生成”在NetBeans观看落日文件夹回来到我的本地回购,所以我知道的连通性远程回购很好。

为什么找不到它?

回答

0

需要把它添加到Maven的字正腔圆,插件:

     <dependencies> 
          <dependency> 
           <groupId>com.sun</groupId> 
           <artifactId>tools</artifactId> 
           <version>1.7</version> 
           <scope>system</scope> 
           <systemPath>C:\Program Files\Java\jdk1.7.0_79\lib\tools.jar</systemPath> 
           <optional>true</optional> 
          </dependency> 
         </dependencies> 

现在看起来是这样的:

<plugin> 
       <groupId>org.codehaus.enunciate</groupId> 
       <artifactId>maven-enunciate-plugin</artifactId> 
       <version>1.25</version> 
       <configuration> 
        <configFile>${basedir}/src/main/webapp/WEB-INF/enunciate.xml</configFile> 
        <compileDebug>false</compileDebug> 
        <addGWTSources>false</addGWTSources> 
        <addActionscriptSources>false</addActionscriptSources> 
       </configuration> 
       <dependencies> 
        <dependency> 
        <groupId>com.sun</groupId> 
        <artifactId>tools</artifactId> 
        <version>1.7</version> 
        <scope>system</scope> 
        <systemPath>C:\Program Files\Java\jdk1.7.0_79\lib\tools.jar</systemPath> 
        <optional>true</optional> 
        </dependency> 
       </dependencies> 

       <executions> 
        <execution> 
         <goals> 
          <goal>assemble</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 

但是,现在有一个新的错误:

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] 

任何人都知道如何解决这个问题?

+0

从8降级到java 7,错误消失。 – user3217883

0

尝试mvn clean compile -Umvn clean install -U

+0

我尝试了两个,但结果相同 – user3217883

+0

其实我得到一个不同的错误与mvn干净安装-e -U。 [INFO] ----------------------------------------------- ------------------------- [错误]编译错误 [信息] --------------- -------------------------------------------------- ------- [信息]汇编语音应用程序的问题。 嵌入式错误:com.sun.tools.apt.mirror.type.ClassTypeImpl无法转换为com.sun.mirror.type。AnnotationType [INFO] --------------------------------------------- --------------------------- [INFO]跟踪 org.apache.maven.lifecycle.LifecycleExecutionException:组装声明应用程序的问题。 – user3217883

0

去你的M2 repository.delete所有jars.Do MVN清洁install.If使用的是Eclipse做一个项目clean.right单击项目 - > maven->更新project.Hope这将起作用

+0

我不能那样做。我使用-o选项以脱机模式运行,因为我继承的pom尝试访问不再存在的回购站,并且没有人知道替换它们的回购站。我已经把所有需要的jar文件从前面的war文件安装到本地repo中。为什么它找不到它们? – user3217883

1

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

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

+0

小修正:版本丢失'.m2/repository/com/sun/mirror/apt/apt-mirror-api/0.1/apt-mirror-api-0.1.jar' –

+0

我只是在文章中输入错误的路径。只是修复它。我昨晚睡在这个问题上,得出了类似的结论。其中一个回报是一个联系,所以我会看看我是否可以上传它。 – user3217883