Because I am constantly busy working on something, I have never had time to actually put everything in words and pictures. But, since you got here, then you must have already seen some part of my work - and this is the way I’m talking.I'm 23, born in Romania, student at UPG Romania in software development field. I started from 0, mostly with basic stuff, and I’m evolving every day to an expert. I'm focused on freelancing projects, from small websites, to really heavy stuff. I know that I look and act differently from most developers, but this is why you will love to work with me! Constantin has posted 42 posts at DZone. You can read more from them at their website. View Full User Profile

How to call an Ant script (part 2 - with parameters)

  • submit to reddit

The method below calls an Ant script with parameters. All you need to pass through is the name (and path) of the Ant script and a Map of parameters – the keys are the parameters names as in the Ant script, and the values are the parameters values:

private boolean runAntScript(String scriptName, Map params) {

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

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

Set keys = params.keySet();
Iterator iteratorKeys = keys.iterator();
while (iteratorKeys.hasNext()) {
String key = (String);
project.setProperty(key, params.get(key));



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.


Published at DZone with permission of its author, Constantin Alin.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)