0

Executing Ant command from Java throws up error

Tried below steps but could not succeed, any help greatly appreciated:

  1. We have java based tool in the project built with ant
  2. Manually we will run the tool by navigating to the java project and run the tool commands as below:
    1. cd /Users/Project
    2. 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.

howlger
  • 31,050
  • 11
  • 59
  • 99
user3356164
  • 783
  • 1
  • 5
  • 6

1 Answers1

0

ant is a batch/shell script:

Due Ant is a Java application, it is preferable to run Ant by the ant-launcher.jar.

howlger
  • 31,050
  • 11
  • 59
  • 99