代码之家  ›  专栏  ›  技术社区  ›  Bostone

爪哇之家被马文弄坏了

  •  37
  • Bostone  · 技术社区  · 16 年前

    我正在用统一的Maven构建来改造现有的Java项目。因为每个项目都是成熟的,并且已经建立了基于蚂蚁的构建 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 执行,这正是我得到的值,但是正如您在错误消息中看到的那样 C:\Java\jdk1.6.0_13\jre
    2. 如果我跑 ant compile 一切都很好

    是不是说也许 maven antrun插件 做一些像 set JAVA_HOME=%JAVA_HOME%\jre ? 我搜索了批处理/生成文件,但找不到更改发生的位置

    2 回复  |  直到 15 年前
        1
  •  21
  •   Lonzak    11 年前

    这是公认答案中外部链接的反面。Codehaus关闭,因此解决方案消失了。作为参考,这里是链接后面的内容-您基本上只需要复制 <dependencies>...</dependencies> 阻止您的antrun插件。。。

    maven antrun插件运行ant,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>
    
        2
  •  18
  •   dvtoever    13 年前

    我在ant build.xml文件中添加了以下属性定义,从而解决了这个问题:

    <property name="build.compiler" value="extJavac"/>
    
    推荐文章