User Tools

Site Tools


tips:java:callant

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tips:java:callant [2009/06/08 11:53] (current)
erik created
Line 1: Line 1:
 +====== Executing Ant tasks programatically ======
  
 +Taken from [[http://​myjavablog.blogspot.com/​2006/​01/​executing-ant-tasks-programatically.html|David'​s blog]].
 +
 +<code java>
 +/*
 + * AntRunner.java
 + */
 +
 +import java.io.File;​
 +import org.apache.tools.ant.DefaultLogger;​
 +import org.apache.tools.ant.Project;​
 +import org.apache.tools.ant.ProjectHelper;​
 +import org.apache.tools.ant.taskdefs.Ant;​
 +
 +
 +public class AntRunner {
 +
 + public AntRunner() {
 + }
 +
 + public static void main(String args[]) throws Exception {
 + File buildFile = new File("/​path/​to/​build.xml"​);​
 + Project p = new Project();
 + p.setUserProperty("​ant.file",​ buildFile.getAbsolutePath());​
 + p.init();
 + ProjectHelper helper = ProjectHelper.getProjectHelper();​
 + p.addReference("​ant.projectHelper",​ helper);
 + helper.parse(p,​ buildFile);
 + DefaultLogger consoleLogger = new DefaultLogger();​
 + consoleLogger.setErrorPrintStream(System.err);​
 + consoleLogger.setOutputPrintStream(System.out);​
 + consoleLogger.setMessageOutputLevel(Project.MSG_INFO);​
 + p.addBuildListener(consoleLogger);​
 + p.executeTarget(p.getDefaultTarget());​
 + }
 +}
 +</​code>​
tips/java/callant.txt · Last modified: 2009/06/08 11:53 by erik