ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <>
Subject [Ant Wiki] Update of "AntOnWindows" by DavidOram
Date Tue, 18 Aug 2009 01:11:09 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Ant Wiki" for change notification.

The following page has been changed by DavidOram:

   * Add your java JDK Path to the user variables as well.  The name should be JAVA_HOME and
the value should be the path to the JDK software on your hard-drive.  (i.e. JAVA_HOME = C:\Program
   * If there is already a PATH variable, edit it and add to it.  Otherwise, create one more
variable named PATH, and add to it ;%ANT_HOME%\bin
+ = 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"/>
+     		<sequential>
+     			<delete file="${user.dir}/runBat.err" failonerror="false"/>
+     			<echo file="${user.dir}/runBat.bat">
+ call @{batch} @{args}
+ if ERRORLEVEL 1 ( 
+    echo %ERRORLEVEL% &gt; ${user.dir}\runBat.err 
+ )
+     			</echo>
+     			<exec executable="cmd">
+ 					<arg value="/c"/>
+ 					<arg value="${user.dir}\runBat.bat"/>
+ 				</exec>    			
+     			<delete file="${user.dir}/runBat.bat"/>
+     		    <fail message="ERROR: @{batch} failed">
+     		        <condition>
+     		            <available file="${user.dir}/runBat.err"/>
+     		        </condition>
+     		    </fail>
+     		</sequential>
+     	</macrodef>
+ 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"

View raw message