ant-user mailing list archives

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

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.

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

Ninju

----- Original Message ----
From: "Balasubramanian, Ravi Shankar" <rbalasub@informatica.com>
To: user@ant.apache.org
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="">
    .
    .
    .
 </target>

"

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

p.addBuildListener(consoleLogger);
p.fireBuildStarted();
p.init();

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

p.executeTarget("start-repository");

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? 

Regards,

Ravi.

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

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message