You can set use the input task to make Ant ask for parameters on the command line at runtime.
<targetThis will display a message and wait.
name = "test1"
description = "testing the input task"
>
<input
message = "Press [Enter] to continue"
/>
</target>
<target
name = "test1"
description = "testing the input task"
>
<input
message = "Type a number"
addproperty = "myNumber"
defaultvalue = "-1"
/>
<echo
message = "You have typed: ${myNumber}" />
</target>
- This will
- display a message
- wait for the user to type in something and / or press return;
- either assign what the user to typed in to the property myNumber, or the default value of “-1″
- display the property in a message.
<target
name = "test3"
description = "testing the input task"
>
<input
message = "Type in a number between 0 and 9999"
addproperty = "myNumber"
defaultvalue = "0"
/>
<condition property="is_number">
<matches pattern="^[1-9]{1,4}$" string="${myNumber}"/>
</condition>
<fail message="Incorrect input (${myNumber}) "
unless="is_number"/>
<echo
message = "You have typed: ${myNumber}" />
</target>
- This will
- display a message
- wait for the user to type in something and / or press return;
- either assign what the user to typed in to the property myNumber, or the default value of “-1″
- run the condition task with the matches regular expression to validate the property myNumber, and put the result of the validation into the is_number property (there is also a regular expression element for more complex validation).
- look at the is_number property and abort the task if it set to false, displaying an error message
- If validation had passed, it displays a message containing the myNumber property

Updates
subscribe to this blog's rss feed'
follow me on twitter
subscribe friendfeed
my delicious bookmarks
my youtube channel