ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Martin <>
Subject launch Ant from Java code
Date Wed, 12 Jan 2011 13:08:35 GMT
Hello and happy new year to you all,

What is the recommended way for launching an Ant script/task from Java code ?

It seems to me that the following URL
rather explains how to launch Ant with java.exe from the command line.
Is it also recommended to launch the main() method from with a Java
code? Or is there a launch API that can be used?

I also found people working directly with the Ant project class. Something like:
Project p = new Project();
p.setBaseDir(getBaseDir(baseDir, buildFile));
p.setUserProperty("ant.file", getBuildFile(buildFile));
try {
	ProjectHelper helper = ProjectHelper.getProjectHelper();
	p.addReference("ant.projectHelper", helper);
	helper.parse(p, buildFile);
	p.executeTarget(null == target ? p.getDefaultTarget() : target);
} catch (BuildException e) {
} finally {

Thank you,


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message