2016-01-11 39 views
0

我有一個Ant項目,它自己構建得很好。我現在試圖將它包裝在一個Maven構建中,它將使用maven-antrun-plugin啓動Ant構建。當我做這個構建失敗,我得到這個錯誤,在Maven中包裝Ant - JAVA_HOME指向JRE,但只與Ant一起工作

[ERROR] C:\Users\bobby\workspace\libraries\build-targets\common-targets.xml:170: 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:\Java\jdk1.8.0_65\jre" 

有很多關於此錯誤的SOF的職位,但我覺得我的是獨一無二的,因爲它只是發生在我的包裹Ant構建中Maven ie,當我只是說$ ant build時,我沒有在同一個項目上得到這個錯誤。

這是我pom.xml中的一部分文件

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <executions> 
       <execution> 
        <phase>process-resources</phase> 
        <configuration> 
         <tasks> 
          <ant antfile="build.xml" target="build" /> 
         </tasks> 
        </configuration> 
        <goals> 
         <goal>run</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>build-helper-maven-plugin</artifactId> 
      <version>1.3</version> 
      <executions> 
       <execution> 
        <id>add-jar</id> 
        <phase>package</phase> 
        <goals> 
         <goal>attach-artifact</goal> 
        </goals> 
        <configuration> 
         <artifacts> 
          <artifact> 
           <file>build/bin/myWarFile.war</file> 
           <type>war</type> 
          </artifact> 
         </artifacts> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

JAVA_HOME環境變量設置爲C:\Java\jdk1.8.0_65

錯誤中提到的文件來自庫我的工作維護我們保留所有罐子的位置。在該文件中這裏是什麼就行170

<target name="compile-src"> 
    <!-- Compile source --> 
    <javac srcdir="${java.src.dir}" 
     destdir="${class.dir}" 
     debug="${debug.flag}" 
     deprecation="${deprecation.flag}" 
     nowarn="${warnings.flag}" 
     optimize="off" 
     source="${source.value}"> 
     <classpath refid="compile.classpath"/> 
    </javac> 
</target> 

源線=是線170

回答

1

這是一個常見問題。嘗試使用這種配置:

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    ... 
    <!-- Add this dependency to your ant-run configuration --> 
    <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> 
    ... 
</plugin> 

Maven使用Java的系統屬性java.home,這是一樣環境變量JAVA_HOME,但使用它由套結對jre計算其java.home子目錄,如目擊。因此,Ant所需的東西根本不在jre目錄中。

但是,此配置可確保正確滿足Ant的插件依賴關係。

-1

您需要指向JDK不是JRE。只要刪除ire並嘗試。

It is currently set to "C:\Java\jdk1.8.0_65\jre" 

如果你的JDK設置 - 另一種解決辦法 - 可以從JDK的lib複製的tools.jar到JRE lib和看看它是否工作。

+0

該帖子明確指出我指向的是JDK而不是JRE。 –

+0

Downvote。?我認爲你在我的評論後編輯了你的帖子,或者可能是在同一時間 – JSR

+0

我的JAVA_HOME環境變量設置爲C:\ Java \ jdk1.8.0_65在原始文章中。我在你的回答後做了筆記,因爲你沒有閱讀整篇文章。 –