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.

1 Answer 1

0

ant is a batch/shell script:

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

Sign up to request clarification or add additional context in comments.

2 Comments

We have to run ant command from iOS/mac, any suggestions please
I have extended the answer for macOS. I recommend the platform-independent solution via ant-launcher.jar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.