【问题标题】:Maven Ant BuildException with maven-antrun-plugin ... unable to find javac compiler带有 maven-antrun-plugin 的 Maven Ant BuildException ...无法找到 javac 编译器
【发布时间】:2011-06-06 09:52:49
【问题描述】:

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

【问题讨论】:

    标签: java maven maven-plugin


    【解决方案1】:

    第一件事:为什么你在install 阶段而不是compile 执行你的ANT 脚本?

    第二件事:尽管您的 JAVA_HOME 指向 JDK,但您的问题可能是由于 Maven 执行 JRE 而不是 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>
    

    【讨论】:

    • 修复链接已损坏。我想这就是为什么他们建议将详细信息放在答案和链接中。
    • @Lukasz - 您要么需要修复此答案,要么将其删除,这是非常无用的链接,现在只能用死链接回答!
    • @JarrodRoberson 感谢您指出这一点。我粘贴了插件的示例配置。
    猜你喜欢
    • 2012-12-19
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    • 1970-01-01
    • 2012-10-21
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    相关资源
    最近更新 更多