Thursday, May 7, 2009

Ant - Passing Argument in Command Line

Ant - Passing Argument in Command Line:

Case 1 : Using own bat file (ant.bat) for executing ant
=======================================================
Passing Arguments in Command Line
C:/ant/apache-ant-1.6.2/bin/ant.bat -DArg4First=SUN -DArg4Second=JAVA

In build.xml file
<project default='testAnt'>
<target name='First'>
<echo message='Input value is: ${Arg4First}' />
</target>

<target name='Second'>
<echo message='Input value is: ${Arg4Second}' />
</target>
</project>

Case 2 : Using another batch file(testCallAnt.bat) for calling ant.bat file
===========================================================================
Inside testCallAnt.bat will be,
C:/ant/apache-ant-1.6.2/bin/ant.bat -buildfile testAnt.xml First Second -DArg4First=SUN -DArg4Second=JAVA

Call the Batch file like this,
c:\Ant\> testCallAnt.bat %1 %2

Eg: c:\Ant\> testCallAnt.bat SUN JAVA

No comments: