ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ninju Bohra <>
Subject Re: Problems with calling an ant java task programatically
Date Fri, 13 Apr 2007 14:29:26 GMT

I don't fully understand your need, but I'm gonna go ahead and give you my $.02 worth :-)

If you want to programmaticaly launch an ANT target from with JAVA code and you don't want
to wait for the target to finish you should be able to merely run the ANT script in a seperate

Process p = Runtime.getRuntime().exec("ANT command line")

You should not have to instatiate an entire ANT project enviroment within your JAVA code...ANT
by design is sychronouous and so when you run a 'target' (via the p.execTarget() call) the
thread the makes the call is hosting the execution and the call will not return until the
target is completely run.

There are other options involving executing the ProjectHelper calls in a seperate thread but
that alot more complex.

The Process object is that is returns should allow you access to every you need (completion
indicator, exit code, and console output)

The Project/ProjectHelper classes as for the developer that need access to the inner working
of the ANT engine and interested in the happenings during a ANT target invocation (IDEs authors,
target developers, debuggers, etc...) and so I don't think you need to go through all the
code you wrote (though it is wonderfully written)

Good Luck


----- Original Message ----
From: "Balasubramanian, Ravi Shankar" <>
Sent: Friday, April 13, 2007 3:21:43 AM
Subject: Problems with calling an ant java task programatically

Hi ,

I am using ant 1.6.5 and 

My ant script is as follows:

<target name="start-repository" description="Start the test repository" depends="">


I am trying to call this target programmatically from a java application
as follows:


File antFile = new File(REPAGENT_ANT_SCRIPT);
Project p = new Project();
DefaultLogger consoleLogger = new DefaultLogger();


ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, new File(p.getUserProperty("ant.file")));


p.fireBuildFinished(new BuildException("BUILD FINISHED"));


When I run this java application, the code waits for the process that
was started by the ant target to end before exiting this method. I do
not want this to happen and I want to continue with the java application
after executing the ant target. 

Can someone let me know how I can accomplish this? 



"Tough times never last, but tough men do..."

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message