java - 从 maven 调用时无法使用 ant 构建

标签 java maven ant build

我有一个 ant 构建文件,它在被自身调用时可以工作。当我从 maven 调用它时,前几个任务执行得很好(init、clean 等),但构建失败:

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

最佳答案

错误表明您没有指向 JDK。您需要将 JAVA_HOME 更改为 JDK 的根而不是 JRE。这样它将能够找到 javac

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

关于java - 从 maven 调用时无法使用 ant 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14663969/

相关文章:

java - 尝试使用从 1 开始的索引创建 ArrayList 时出现索引越界异常

Java 邮件逻辑 : Could not convert socket to TLS

maven - .java不在项目的classpath中,只报语法错误

java - 从 SCONS 运行 ANT 脚本

java - Android将文本文件(.txt)读入字符串数组

使用 Eclipse ADT 的 Java

java - 如何解决 Eclipse 中的循环项目依赖关系。有什么方法可以使依赖项之一仅运行吗?

maven-2 - 在 Maven 中覆盖 'clean' 生命周期

ant - 如何使用Ant在文件末尾 append 一些文本?

java - 如何从 Ant 构建文件设置 Eclipse 构建路径和类路径?