File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes JVM terminates when callling ant script from java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "JVM terminates when callling ant script from java" Watch "JVM terminates when callling ant script from java" New topic
Author

JVM terminates when callling ant script from java

Abdul Mohsin
Ranch Hand

Joined: Apr 26, 2007
Posts: 111

Hi,

I am trying to run ant script from java code like this:
Launcher.main(new String[]{"-f","C:\\Projects\\ant_projects\\chap1\\Echo2.xml"});
System.out.println("*********** In End");

and able to successfully call the ant script but it looks that JVM is terminated after calling ant script as the logger "in End" is not printed in the console.

Is there any way to change this default behariour of ant to exit the JVM?

Please help.


Regards, Abdul Mohsin
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

Looking at the source code, Launcher.main calls System.exit if there is a non-zero exit code. You could try calling the run method instead, like this:

int code = new Launcher().run(new String[]{...});


JBoss In Action
 
Consider Paul's rocket mass heater.
 
subject: JVM terminates when callling ant script from java