JAVA_HOME被Maven破坏了

时间:2010-01-07 18:27:21

标签: maven-2 ant maven

我正在使用统一的Maven构建来改进大量现有的Java项目。由于每个项目都已成熟并已建立基于Ant的构建,因此我使用maven-antrun-plugin执行现有build.xml,如下所示:

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <configuration>
                        <tasks>
                            <ant antfile="build.xml" target="compile" />
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

当我运行mvn compile构建失败时显示以下消息:

[INFO] An Ant BuildException has occured: The following error occurred 
       while executing  this line:
build.xml:175: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Java\jdk1.6.0_13\jre"

让我感到困惑的是

  1. 我有JAVA_HOME=C:\Java\jdk1.6.0_13作为我的环境设置的一部分,当mvn.bat被执行时,这正是我得到的值,但正如您在错误消息中看到的那样,它出现为{{1} }
  2. 如果我运行C:\Java\jdk1.6.0_13\jre,所有内容都可以正常编译
  3. 这是否意味着ant compile可能会像maven-antrun-plugin这样做?我搜索了我的批处理/构建文件,我找不到发生这种变化的地方

2 个答案:

答案 0 :(得分:21)

在接受的答案中,这是外部链接的缺点。 Codehaus关闭,因此解决方案消失了。在这里参考链接背后的内容 - 你基本上只需要将<dependencies>...</dependencies>块复制到你的antrun插件......

maven-antrun-plugin运行ant,JAVA_HOME设置为JDK的 jre 子目录,即使整个运行的JAVA_HOME是JDK。  其他地方有关于如何在项目级别为JDK的tools.jar创建依赖关系的文档,但这并没有帮助antrun,这是一个插件。  以下简介完成了这项工作。 &#39; ..&#39;在路上匆匆走过了'jre&#39;目录到lib目录。

<profiles>
      <profile>
          <id>tools.jar</id>
          <build>
            <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-antrun-plugin</artifactId>
              <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>
            </plugin>
            </plugins>
          </build>
      </profile>

答案 1 :(得分:16)

我能够通过在ant build.xml文件中添加以下属性定义来解决这个问题:

<property name="build.compiler" value="extJavac"/>
相关问题