Passing an unknown number of parameters to Ant

D

David Portabella

HEllo,

You can pass parameters from the command line to your ant build file
by using properties.
Using ant -Dname=value lets you define values for properties on the
Ant command line.
These properties can then be used within your build file as any normal
property: ${name} will put in value.


However,
Let's say that I have the following java program:
++++++++++++++
class Test {
public static void main(String argv[]) {
for (int i = 0; i < argv.lenght;i++)
System.out.println("param " + i + ": " + argv);
}
}
++++++++++++++

and I have the following ant file:
++++++++++++++
<project basedir=".">
<target name="run">
<java fork="true" classname="Test"/>
</target>
</project>
++++++++++++++

How do I need to modify the ant file so that executing "ant run one
two three" from the command line, produces:
++++++++++++++
param 1: one
param 2: two
param 3: three
++++++++++++++

(and it works for any number of parameters)



Many thanks,
DAvid
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top