Platinum Partner
java

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

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());
myLogger.setErrorPrintStream(System.err);
myLogger.setOutputPrintStream(System.out);
myLogger.setMessageOutputLevel(Project.MSG_INFO);

project.addBuildListener(myLogger);

try {
project.fireBuildStarted();
project.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
project.addReference("ant.projectHelper", helper);
helper.parse(project, buildFile);
project.executeTarget(project.getDefaultTarget());
project.fireBuildFinished(null);
} catch (Exception e) {
project.fireBuildFinished(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

{{ tag }}, {{tag}},

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

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}