shellantscriptingwebsphere-mq-ftereturn-code

How to run ant script from a shell script?


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?


Solution

  • 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