Windows installation

There are two ways to install Ant on Windows.


For a quick and easy installation, use the Windows installer for Apache Ant. This installation of Ant will automatically install Ant into the C:\Program Files\WinAnt path by default. It also sets up your ANT_HOME and PATH variables to point at the new installation.

Manual Install

Executing batch files

When executing batch files on windows through the <exec> task you commonly execute the cmd.exe program to run the batch file. However this means that any ERRORLEVEL reported by the batch file is not propagated up to ant. If you want to run a batch file, and fail if the batchfile sets the ERRORLEVEL, then you can try this recipe:

        When running a batch files from ant, it cannot detect the %ERRORLEVEL% as set by 'exit /B 1'
        This macro is inspired from 
        and provides a wrapper to detect this correctly
        <macrodef name="runBat">
                <attribute name="batch"/>
                <attribute name="args"/>
                        <delete file="${user.dir}/runBat.err" failonerror="false"/>
                        <echo file="${user.dir}/runBat.bat">
call @{batch} @{args}
   echo %ERRORLEVEL% &gt; ${user.dir}\runBat.err 
                        <exec executable="cmd">
                                        <arg value="/c"/>
                                        <arg value="${user.dir}\runBat.bat"/>
                        <delete file="${user.dir}/runBat.bat"/>
                    <fail message="ERROR: @{batch} failed">
                            <available file="${user.dir}/runBat.err"/>

And to execute a batch file: <runBat batch="mycommand.bat" args="foo bar moo"/>

This will fail the ant script if mycommand.bat fails, ie: if the batchfile executes "exit /b 1"

AntOnWindows (last edited 2011-06-13 09:50:38 by antoine)