dcsimg
calling an ant task programatically.
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   yogesh_seth
Posted On:   Friday, July 8, 2005 05:15 PM

how do i run an ant task (i need to run junit task) through JAVA code?

cheers
yogesh

Re: calling an ant task programatically.

Posted By:   ross_perry  
Posted On:   Friday, July 15, 2005 01:19 PM

You need to use the ant lib Project class.
And then configure it.

import org.apache.tools.ant.*;

Project proj = new Project();
proj.setBaseDir(dir);
//set properties
Properties prop = new Properties();
prop.load( new FileInputStream( "build.properties"));
for( Enumeration en = prop.keys(); en.hasMoreElements(); ) {
String key = ( String) en.nextElement();
proj.setProperty( key, prop.getProperty( key));
}

proj.init();
ProjectHelper.configureProject(proj, new File dir, "build.xml"));
_project.executeTarget(yourTargetName);

Re: calling an ant task programatically.

Posted By:   Nick_Maiorano  
Posted On:   Saturday, July 9, 2005 10:26 PM

Yogesh,



I don't see the need for doing this as this is best handled using a script file. Anyway, running an ant task is like running any other o/s command: you need to use the Runtime class. More specifically, use the exec method to fork out an o/s process.

About | Sitemap | Contact