title: Ant class path error when programmatically building Netbeans platform application
body: <p>I want to run a Netbeans 7.3 platform application (let's name it app A) from another Java application (app B). To do this, in B's code I'm invoking the Ant library as follows:</p>
  
  <pre><code>Path pathA = ... // where the A's sources are
  Path fileBuild = pathA.resolve("build.xml");
  Project p = new Project();
  p.setUserProperty("ant.file", fileBuild.toFile().getAbsolutePath());
  p.init();
  ProjectHelper helper = ProjectHelper.getProjectHelper();
  p.addReference("ant.projectHelper", helper);
  helper.parse(p, buildFile);
  p.setDefault("run");
  p.executeTarget(p.getDefaultTarget());
  </code></pre>
  
  <p>Unfortunately, the error I'm getting is:</p>
  
  <pre><code>C:\Program Files\NetBeans 7.3\harness\suite.xml:184: The following error occurred while executing this line:
  C:\Program Files\NetBeans 7.3\harness\common.xml:217: 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:\Program Files (x86)\Java\jdk1.7.0_45\jre"
      at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:568)
      at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:443)
      at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:306)
      at org.apache.tools.ant.taskdefs.SubAnt.execute(SubAnt.java:221)
      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
      at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
      at org.apache.tools.ant.Task.perform(Task.java:348)
      at org.apache.tools.ant.Target.execute(Target.java:435)
      at org.apache.tools.ant.Target.performTasks(Target.java:456)
      at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
      at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
  ...
  </code></pre>
  
  <p>The JAVA_HOME variable is set correctly both as system path variable and in netbeans config file and points to <code>C:\Program Files (x86)\Java\jdk1.7.0_45</code>.</p>
  
  <p>The question is, what am I missing? When running the app A from Netbeans menu, everything runs fine, so what should I append to the build file/ant settings to achieve A runs from B's code execution?</p>
  
  <p>Thanks in advance!</p>
  
  <hr>
  
  <p>Edit: I managed to get a more precise error stack, maybe this can help.</p>
  
  <pre><code>Error on test cases execution.
  C:\Program Files\NetBeans 7.3\harness\common.xml:217: 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:\Program Files (x86)\Java\jdk1.7.0_45\jre"
      at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:130)
      at org.apache.tools.ant.taskdefs.Javac.findSupportedFileExtensions(Javac.java:984)
      at org.apache.tools.ant.taskdefs.Javac.scanDir(Javac.java:961)
      at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:932)
      at org.netbeans.nbbuild.CustomJavac.execute(CustomJavac.java:105)
      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
      at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
      at org.apache.tools.ant.Task.perform(Task.java:348)
      at org.apache.tools.ant.Target.execute(Target.java:435)
      at org.apache.tools.ant.Target.performTasks(Target.java:456)
      at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
      at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
      at odoetest.server.ServerInvokerAnt.start(ServerInvokerAnt.java:48)
      at odoetest.EntryPoint.invokeTests(EntryPoint.java:58)
      at odoetest.EntryPoint.main(EntryPoint.java:38)
  </code></pre>
  
  <hr>
  
  <p>Edit-2: I don't have any separate ant installation and use the ant delivered with Netbeans. When I run <code>ant -diagnostics</code>, I get this <a href="http://pastebin.com/1vVLKJzY" rel="nofollow">info</a>. When I invoke the build or run job from the command line like</p>
  
  <pre><code>ant -f /path/to/build.xml run
  </code></pre>
  
  <p>no errors are thrown, the program starts. I just can't do the exact same thing from java code from above.</p>