【问题标题】:Can't build with ant when invoked from maven从 maven 调用时无法使用 ant 构建
【发布时间】:2013-02-02 16:30:03
【问题描述】:

我有一个 ant 构建文件,它在自己调用时可以工作。当我从 maven 调用它时,前几个任务执行良好(初始化、清理等),但构建失败:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (compile) on project maven-stream: An Ant BuildException has occur
ed: The following error occurred while executing this line:
[ERROR] C:\maven_projects\cm\Qlarius Underwriter\build.xml:24: 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:\Program Files\Java\jdk1.7.0_07\jre"
[ERROR] around Ant part ...<ant antfile="C:\maven_projects\cm/Qlarius Underwriter/build.xml">... @ 4:69 in C:\maven_projects\cm\target\antrun\build-ma
in.xml

为什么ant在直接调用而不是通过maven时会找到java?

pom.xml 文件的 ant 部分是:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
      <execution>
        <id>compile</id>
        <phase>compile</phase>
        <configuration>
          <target>
            <ant antfile="${basedir}/Qlarius Underwriter/build.xml">
              <target name="LifeQuote"/>
            </ant>
          </target>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
</plugin>

【问题讨论】:

    标签: java maven ant build


    【解决方案1】:

    正如错误所暗示的,您没有指向 JDK。您需要将 JAVA_HOME 更改为 JDK 的根目录,而不是 JRE。这样它就可以找到javac

    其他任务initclean如果不使用javac可能会没问题

    【讨论】:

    • 我指的是 JDK。如果不是,则直接从 ant 调用时构建将无法工作。我无法确定为什么从 maven 而不是 ant 调用时找不到 jdk
    • C:\maven_projects\cm>echo %java_home% C:\Program Files\Java\jdk1.7.0_07
    • 你需要这个 -Djava.home=${JAVA_HOME} 和 mvn
    • 我在 pom.xml 文件的 ant 区域添加了以下内容,似乎解决了这个问题: com.suntools 1.7.0system${java.home}/../lib/tools.jar依赖>
    猜你喜欢
    • 2011-10-16
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2010-11-30
    • 1970-01-01
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多