gpt4 book ai didi

java - 带有 maven-antrun-plugin 的 Maven Ant BuildException ...无法找到 javac 编译器

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:46:22 55 4
gpt4 key购买 nike

我正在尝试让 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>

关于java - 带有 maven-antrun-plugin 的 Maven Ant BuildException ...无法找到 javac 编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4645012/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com