簡體   English   中英

使用maven-antrun-plugin的Maven Ant BuildException ...無法找到javac編譯器

[英]Maven Ant BuildException with maven-antrun-plugin … unable to find javac compiler

我正在嘗試讓Maven為一些遺留代碼調用ANT構建。 ant構建通過ant正確構建。 但是,當我使用maven ant插件調用它時,它失敗並出現以下錯誤:

[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的Maven代碼是

<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>

第一件事:為什么在install階段而不是在compile執行ANT腳本?

第二件事:你的問題可能是因為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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM