Executing Ant command from Java throws up error
Tried below steps but could not succeed, any help greatly appreciated:
- We have java based tool in the project built with ant
- Manually we will run the tool by navigating to the java project and run the tool commands as below:
cd /Users/Project
ant
command
Manually above command runs fine, but when we try the same to execute from Java code:
String[] cmd = { "ant run.loader -Dchangeuser=999-Dt=1-Dsl=0-Dpath=PathofInputFile/FileName.txt | tee log.txt", "-c", "//Users//ProjDir" };
Process p = Runtime.getRuntime().exec(cmd);
Above Java code generated error as follows :
java.io.IOException: Cannot run program "ant -v": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:485)
Please Note, we have configured Ant path in the PATH variable.
Any help or suggestions are greatly appreciated.