Over a million developers have joined DZone.

How to call an Ant script (part 1 - without parameters)

DZone's Guide to

How to call an Ant script (part 1 - without parameters)

· Java Zone ·
Free Resource

Take 60 minutes to understand the Power of the Actor Model with "Designing Reactive Systems: The Role Of Actors In Distributed Architecture". Brought to you in partnership with Lightbend.

The method below calls an Ant script without parameters. All you need to pass through the name and path of the Ant script:

private boolean runAntScript(String scriptName) {

File buildFile = new File(scriptName);
Project project = new Project();
DefaultLogger myLogger = new DefaultLogger();

project.setUserProperty("ant.file", buildFile.getAbsolutePath());


try {
ProjectHelper helper = ProjectHelper.getProjectHelper();
project.addReference("ant.projectHelper", helper);
helper.parse(project, buildFile);
} catch (Exception e) {
return false;

return true;

You will need the ant libraries in the application classpath. Notice that the above example sends the script output to default System.out and runs the default script start target.


From http://e-blog-java.blogspot.com/2011/04/how-to-call-ant-script-part-1-without.html

Learn how the Actor model provides a simple but powerful way to design and implement reactive applications that can distribute work across clusters of cores and servers. Brought to you in partnership with Lightbend.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}