2010-01-07 143 views
36

我使用统一的Maven构建改造了大量现有的Java项目。由于每个项目成熟,并已建立了基于Ant构建所有我使用maven-antrun-plugin执行现有build.xml如下:JAVA_HOME被Maven破坏

 <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是EXA ctly值我得到,但是当你在错误信息中看到它出来作为C:\Java\jdk1.6.0_13\jre
  2. 如果我运行ant compile一切编译就好

这是否意味着或许maven-antrun-plugin确实像set JAVA_HOME=%JAVA_HOME%\jre?我搜索我的批处理/建造文件,我无法找到此发生变化

回答

13

我能够通过将以下属性定义在我的Ant build.xml文件以解决此问题:

<property name="build.compiler" value="extJavac"/> 
18

那向下接受答案中的外部链接的一面。 Codehaus关闭,因此解决方案消失了。对于参考这里的链接后面的内容 - 你基本上只需要到<dependencies>...</dependencies>块复制到您的antrun插件...

Maven的-antrun-插件运行蚂蚁用JAVA_HOME设置为JRE子目录的JDK即使整个运行的JAVA_HOME是JDK。 其他地方有关于如何在项目级别为JDK的tools.jar创建依赖项的文档,但是这对插件antrun没有帮助。 以下配置文件完成这项工作。路径中的'..'牵着'jre'目录到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

感谢您扩大断开的链接! – wrgrs 2015-08-28 14:36:36

+0

您先生,是互联网英雄,谢谢,我正在寻找这个小时。有用。我只是改为java版本1.8.0。 这应该是现在接受的答案! – Hoto 2015-09-11 16:48:06