title: Setting JAVA_HOME when running Ant from Java
body: <p>The reason is long and boring, but I need to run an Ant script to compile Java 1.5 code from a Java 1.4 app.  I keep getting this error, though:</p>
  
  <pre><code>BUILD FAILED
  
  build.xml:16: 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:\j2sdk1.4.2_16\jre"
  </code></pre>
  
  <p>In my code, I have:</p>
  
  <pre><code>Project p = new Project();
  p.setUserProperty("ant.file", buildFile.getAbsolutePath());
  p.setProperty("java.home", "C:\Program Files\Java\jdk1.6.0_04");
  p.fireBuildStarted();
  p.init();
  // so on and so forth
  </code></pre>
  
  <p>but it ignores it.  I've also tried p.setUserProperty(String, String), but that doesn't do the trick, either.  Is there a way to do it without launching a separate process?</p>