JAVA_HOME得到由Maven的错位 [英] JAVA_HOME gets mangled by Maven

查看:135
本文介绍了JAVA_HOME得到由Maven的错位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一堆翻新现有的Java项目的统一Maven构建。由于每个项目成熟,并已建立了基于Ant构建所有我使用 Maven的antrun-插件执行现有的的build.xml 如下:

I'm retrofitting bunch of existing Java projects with unified Maven build. Since each project is mature and has established Ant based build all I'm using maven-antrun-plugin to execute existing build.xml as follows:

        <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编译生成失败此消息:

When I run mvn compile build fails with this message:

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

令我百思不解的是

What puzzles me is


  1. JAVA_HOME = C:\\的Java \\ jdk1.6.0_13 我的环境设置的一部分,在 mvn.bat 执行,这正是价值我得到,但是当你在错误信息中看到它出来作为 C:\\的Java \\ jdk1.6.0_13 \\ jre的

  2. 如果我跑蚂蚁编译一切编译就好了

  1. I have JAVA_HOME=C:\Java\jdk1.6.0_13 as part of my environment setup and when mvn.bat is executed that is exactly value I'm getting, however as you see in the error message it comes up as C:\Java\jdk1.6.0_13\jre
  2. If I run ant compile everything compiles just fine

这是否意味着也许 Maven的antrun-插件做类似设置JAVA_HOME =%JAVA_HOME%\\ jre的 ?我搜索我的批处理/建造文件,我无法找到此变化发生

Does it mean that perhaps maven-antrun-plugin does something like set JAVA_HOME=%JAVA_HOME%\jre? I searched my batch/build files I can't find where that change occurs

推荐答案

多数民众赞成在接受的答案外部链接的一面。 codehaus关闭,因此该解决方案已经一去不复返了。仅供参考这里的链接后面的内容 - 你基本上只需要复制&LT;依赖&GT; ...&LT; /依赖性&GT; 阻止与antrun插件...

Thats the down side of external links in an accepted answer. Codehaus shut down and thus the solution is gone. For reference here's the content behind the link - you basically only need to copy the <dependencies>...</dependencies> block to your antrun plugin...

的Maven的antrun-插件运行与蚂蚁JAVA_HOME设置为 JRE 的JDK子目录,即使JAVA_HOME整体运行是一个JDK。
 有文档有关如何创建在项目级别为JDK的tools.jar中的依赖其他地方,但这并不助阵antrun,这是一个插件。
 以下配置文件做这项工作。过去的JRE目录下的lib目录路径中的'..'撩起了。

The maven-antrun-plugin runs ant with JAVA_HOME set to the jre subdirectory of the JDK, even if the JAVA_HOME for the overall run is a JDK. There is documentation elsewhere about how to create a dependency at the project level for the JDK's tools.jar, but this does not help out antrun, which is a plugin. The following profile does the job. The '..' in the path hauls up past the 'jre' directory to the lib directory.

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

这篇关于JAVA_HOME得到由Maven的错位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆