2011-01-10 157 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

相關問題