I want to execute an ant file from java. So i decided to use Runtime.getRuntime().exec()
to achieve this. My java file will looks something like below,
Process p = Runtime.getRuntime().exec("cmd /c start ant mytarget -Darg1="+arg1+" -Darg2="+arg2+" ", null, new File("E:/ant_demo"));
System.out.println("Ant file executed");
...
...
..
System.out.println("Completed");
My goal is to run the ant file available in the path E:/ant_demo with few arguments. Once after completing the ant file, the remaining code should be executed.
When i run this code, a separate command prompt window is opened for ant and the remaining code is also getting executed in parallel before the ant file is completed. In order to make the code to wait until the ant is completed, i changed my code as below,
Process p = Runtime.getRuntime().exec("cmd /c start /wait ant mytarget -Darg1="+arg1+" -Darg2="+arg2+" ", null, new File("E:/ant_demo"));
p.waitFor();
System.out.println("Ant file executed");
...
...
..
System.out.println("Completed");
After this change, even after the ant is completed the remaining code is not getting executed and the command prompt used for ant is stayed open. When i close the command prompt used for ant manually, then the remaining codes are getting executed.
How to make the command prompt used by ant to close automatically? or how to change my code to run the ant file and execute the remaining code once after the ant is completed?
I tried to achieve this in many ways, but still facing this problem.