How to run ant script from a shell script?

trilawney picture trilawney · Jul 19, 2011 · Viewed 9.4k times · Source

I need to run an ant script from a shell script and if the ant script is executed successfully I must get the return code 0 or in case of failure 1. Can anyone tell me how can this be achieved?

Answer

Jacob picture Jacob · Jul 19, 2011
cd ~/yoursourcedir/
ant
if [[ $? -ne 0 ]]
then
    echo "error happend"
fi

$? contains the error code of your last command, in this case ant. -ne 0 means not equal 0, so if any error happened, execute the echo.

You can specify the standard paramters to ant, i.e. your buildfile:

ant -buildfile build.xml

Summary of ant run options