Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Ant compiler to JDK 1.6

Tags:

java

ant

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

<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 </code> gives: <code>
/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?

like image 688
user847352 Avatar asked Jul 18 '12 23:07

user847352


People also ask

Which version of Java does ant use?

1. Which version of Java is required to run Apache Ant? You will need Java installed on your system, version 1.8 or later required. The later the version of Java, the more Ant tasks you get.

Is Ant compatible with Java 11?

Ant Migration Tool version 51.0 and later requires Java version 11 or later.

How do I check ant version?

Check your installation by opening a command line and typing ant -version into the commend line. The system should find the command ant and show the version number of your installed Ant version.


1 Answers

In the javac task, try specifying the Java compiler by setting the executable attribute as follows:

<property name="JDK1.6.dir" location="/usr/lib/jvm/java-6-openjdk-amd64" />
<property name="javac1.6" location="${JDK1.6.dir}/bin/javac" />

<target name="compile-tests">
  <javac executable="${javac1.6}" 
      fork="yes"
      includeantruntime="false" 
      srcdir="${test.dir}"
      destdir="${build.dir}" >
    <classpath refid="class.path" />
  </javac>
</target>
like image 154
Christopher Peisert Avatar answered Oct 07 '22 04:10

Christopher Peisert