2011-01-10 123 views
5

我想让Maven调用一些ANT构建一些遗留代码。蚂蚁构建通过蚂蚁正确构建。然而,当我把它使用Maven的蚂蚁插件时,出现以下错误:Maven Ant BuildException与maven-antrun-plugin ...无法找到javac编译器

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run  (default) on project CoreServices: An Ant BuildException has occured: The following error occurred while executing this line: 
[ERROR] C:\dev\projects\build\build.xml:158: The following error occurred while executing this line: 
[ERROR] C:\dev\projects\build\build.xml:62: The following error occurred while executing this line: 
[ERROR] C:\dev\projects\build\build.xml:33: The following error occurred while executing this line: 
[ERROR] C:\dev\projects\ods\build.xml:41: Unable to find a javac compiler; 
[ERROR] com.sun.tools.javac.Main is not on the classpath. 
[ERROR] Perhaps JAVA_HOME does not point to the JDK. 
[ERROR] It is currently set to "C:\bea\jdk150_11\jre" 

我的javac存在于C:\ BEA \ jdk150_11 \ bin和这适用于所有其他的事情。我不知道Maven在哪里获得这个版本的JAVA_HOME。 Windows环境变量中的JAVA_HOME被设置为C:\ bea \ jdk150_11 \,因为它应该是。

,我使用调用build.xml文件是

<build> 
    <plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.6</version> 

    <executions> 
      <execution> 
      <phase>install</phase> 
      <configuration> 

       <target> 
    <ant antfile="../build/build.xml" target="deliver" > 
    </ant> 
       </target> 
      </configuration> 
      <goals> 
       <goal>run</goal> 
      </goals> 
      </execution> 
     </executions> 
    </plugin> 
    </plugins> 
    </build> 

回答

15

第一件事Maven的代码:你为什么在install阶段执行Ant脚本,而不是在compile

第二件事:您的问题可能是由于Maven执行了JRE而不是JDK,尽管您的JAVA_HOME指向了JDK。要解决这个问题,你需要手动调整maven-antrun-plugin的依赖关系。这只是一个例子:

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.6</version> 
    <dependencies> 
     <dependency> 
      <groupId>com.sun</groupId> 
      <artifactId>tools</artifactId> 
      <version>1.5.0</version> 
      <scope>system</scope> 
      <systemPath>${java.home}/../lib/tools.jar</systemPath> 
     </dependency> 
    </dependencies> 
    <executions> 
     <execution> 
      <phase>compile</phase> 
      <configuration><target><ant/></target></configuration> 
      <goals><goal>run</goal></goals> 
     </execution> 
    </executions> 
</plugin> 
+4

修复链接已损坏。我想这就是为什么他们建议把答案中的细节以及链接。 – wrgrs 2015-08-28 14:22:30

相关问题