Skip to content
Advertisement

How to change the Java JDK version in an Ant task?

I need to compile my source code to be compatible with JRE 1.6. However, when I attempt to set the compiler attribute of the javac task to be javac1.6, Ant will still compile my code with javac1.7. I have also tried setting the compiler version to be “modern” and that did not work.

<target name="compile-tests">
    <javac compiler="javac1.6" includeantruntime="false" srcdir="${test.dir}" destdir="${build.dir}" >
        <classpath refid="class.path" />
    </javac>
</target>

My JAVA_HOME is set to JDK 1.6:

echo $JAVA_HOME
/usr/lib/jvm/java-6-openjdk-amd64/

My ant version is: Apache Ant(TM) version 1.8.2

According to this post, Ant uses its own compiler. How do I override the Ant default?

Also, according to this post and the Ant documentation, I can set the global build.compiler property. What do I set that property to be and how might I do that?

Advertisement

Answer

I think Ant compiler attribute is just to know which properties are supported by the compiler. In javac in general the attribute or option to pass to the compiler is target.

You should not even need to have a Java 6 compiler installed.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement