0

I'm trying to run Ant from a Java program. This works:

// Compile project
ProcessBuilder pb =
        new ProcessBuilder("/usr/local/Cellar/ant/1.9.6/libexec/bin/ant", "-f", pathToProject + "build.xml");
Process p = pb.start();
p.waitFor();

However, this program will be used on machines other than my own, so I'd rather instantiate the ProcessBuilder like this:

new ProcessBuilder("ant", "-f", pathToProject + "build.xml");

Although ant -f build.xml works on my Mac terminal, placing the above code in my program outputs java.io.IOException: Cannot run program "ant": error=2, No such file or directory.

How can I programmatically show ProcessBuilder where Ant is located? This program will be run on OS X and possibly Ubuntu.

Note: This question is not Ant-specific. I need use ProcessBuilder to invoke other command-line tools as well.

1 Answer 1

0

Inject the absolute path of the ant to ProcessBuilder by making it customizable through properties file.This way you can run on multiple environments just by providing the corresponding path in the properties file.

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

Comments

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.