title: How to change the Java JDK version in an Ant task?
body: <p>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 <code>javac</code> task to be <code>javac1.6</code>, Ant will still compile my code with <code>javac1.7</code>. I have also tried setting the compiler version to be &quot;modern&quot; and that did not work.</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;target name=&quot;compile-tests&quot;&gt;
      &lt;javac compiler=&quot;javac1.6&quot; includeantruntime=&quot;false&quot; srcdir=&quot;${test.dir}&quot; destdir=&quot;${build.dir}&quot; &gt;
          &lt;classpath refid=&quot;class.path&quot; /&gt;
      &lt;/javac&gt;
  &lt;/target&gt;
  </code></pre>
  <p>My <code>JAVA_HOME</code> is set to JDK 1.6:</p>
  <pre class="lang-sh prettyprint-override"><code>echo $JAVA_HOME
  /usr/lib/jvm/java-6-openjdk-amd64/
  </code></pre>
  <p>My ant version is: <code>Apache Ant(TM) version 1.8.2 </code></p>
  <p>According to <a href="https://stackoverflow.com/questions/10543336/which-javac-exe-is-used-by-ant-javac-task">this post</a>, Ant uses its own compiler. How do I override the Ant default?</p>
  <p>Also, according to <a href="https://stackoverflow.com/questions/235363/override-the-compiler-attribute-in-an-ant-javac-task">this post</a> and the Ant documentation, I can set the global <code>build.compiler</code> property. What do I set that property to be and how might I do that?</p>