My program getting command line arguments. How can I pass it when I use Ant?
+1
A:
Can you be a bit more specific about what you're trying to do and how you're trying to do it?
If you're attempting to invoke the program using the <exec>
task you might do the following:
<exec executable="name-of-executable">
<arg value="arg0"/>
<arg value="arg1"/>
</exec>
Richard Cook
2010-09-16 21:18:31
Like: ant run arg0 arg1
Victoria
2010-09-16 21:35:46
+2
A:
Extending Richard Cook's answer ur ant task will look like
to run any program (including but not limited to java programs)
<target name="run">
<exec executable="name-of-executable">
<arg value="${arg0}"/>
<arg value="${arg1}"/>
</exec>
</target>
to run a java program from a jar file
<target name="run-java">
<java executable="path for jar">
<arg value="${arg0}"/>
<arg value="${arg1}"/>
</java>
</target>
and u call it like
ant -Darg0=Hello -Darg1=World run
If u tried
ant run arg0 arg1
then ant would try to run targets arg0 and arg1.
emory
2010-09-16 22:13:39
A:
The only effective mechanism for passing parameters into a build is to use Java properties:
ant -Done=1 -Dtwo=2
The following example demonstrates how you can check and ensure the expected parameters have been passed into the script
<project name="check" default="build">
<condition property="params.set">
<and>
<isset property="one"/>
<isset property="two"/>
</and>
</condition>
<target name="check">
<fail unless="params.set">
Must specify the parameters: one, two
</fail>
</target>
<target name="build" depends="check">
<echo>
one = ${one}
two = ${two}
</echo>
</target>
</project>
Mark O'Connor
2010-09-16 22:40:59
if number of args is not constant, then probably the best u can do is ant -Dvarargs="Hello World. It is Good to Meet You!" run
emory
2010-09-17 21:45:14