I’ve been working with the ANT API whilst putting together a build tool (long story) recently. There isn’t a whole lot of documentation available on the ‘net (in fact, there’s explicitly little documentation in cases), so here are two things that took me a moment or two to work out.
For various reasons, our build XML is called builder.xml – this worked fine up until the first javac call, following which ANT began looking for build.xml .
To correct this, you can set the ant.file property to correctly specify your build file.
File buildFile = new File("builder.xml");
JAVA_HOME not set
Next, the ANT Java API insisted that my JAVA_HOME wasn’t set. I was fairly certain that it was.
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
After reading the message with somewhat more comprehension, I realized that I just needed to include tools.jar on the command line. Issue sorted.
For anyone looking for the actual build code,
File buildFile = new File("projectName + "\\builder.xml");
Project p = new Project();
ByteArrayOutputStream standardOutput = new ByteArrayOutputStream();
ByteArrayOutputStream errorOutput = new ByteArrayOutputStream();
DefaultLogger consoleLogger = new DefaultLogger();
catch (BuildException ex)
this.failed = true;