使用maven-antrun-plugin的Maven Ant BuildException ...无法找到javac编译器

Rob*_*ely 6 java maven-plugin maven

我正在尝试让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"
Run Code Online (Sandbox Code Playgroud)

我的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>
Run Code Online (Sandbox Code Playgroud)

Luk*_*asz 16

第一件事:为什么你要分阶段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>
Run Code Online (Sandbox Code Playgroud)

  • 修复链接已损坏.我想这就是为什么他们建议把细节放在答案和链接中. (4认同)
  • @Lukasz - 您需要修复此答案或删除它,它是相当无用的链接现在只回答死链接! (2认同)