用ant的javac编译java报错:Perhaps JAVA_HOME does not point to the JDK

ant的linux.xml 里有个javac编译命令:
<target name="compile" depends="init">

    <echo>JAVA_HOME: ${JAVA_HOME}</echo>

    <javac srcdir="${app.src}" destdir="${app.build}" deprecation="on" encoding="UTF-8">

        <classpath>

            <path refid="classpath.path" />

        </classpath>

    </javac>

    <copy todir="${app.build}" encoding="UTF-8">

        <fileset dir="${app.src}" excludes="**/.java,**/.svn" />

    </copy>

</target>
报错内容:
BUILD FAILED

/home/xxx/linux.xml:64: 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 "/usr/lib/jvm/java-8-openjdk-amd64/jre"
遇到这个问题,经过我反复测试,得到的结果就是ant找不到javac,所以不能执行javac命令。
打开apache ant的官网查配置说明。
ant的官网:http://ant.apache.org/manual/Tasks/javac.html
If you want to run thejavaccompiler of a different JDK, you should tell Ant, where to find the compiler and which version of JDK you will be using so it can choose the correct command line switches. The following example executes a JDK 1.1javacin a new process and uses the correct command line switches even when Ant is running in a JVM of a different version:
<javac srcdir=”${src}”
       destdir=”${build}”
       fork=”yes”
       executable=”/opt/java/jdk1.1/bin/javac”
       compiler=”javac1.1″/>
看到这个我就知道,我只需要使用 fork=”yes” executable=”jdk/bin/javac” 就能够搞定我的问题了。
然后,搞定。

要发表评论,您必须先登录