Tag Archives: promt

Passing command line arguments to ant script file

ant-promt
You may know such ant task as Input – http://ant.apache.org/manual/Tasks/input.html.
It promts user to enter some stuff. But what if you want to run script without promt but using command line arguments only?
Ant presents the awesome solution: just use -D option!
See more at http://ant.apache.org/manual/running.html

Consider we have ant script run.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>

<project name="someProject" default="someTask" basedir=".">
    <taskdef resource="net/sf/antcontrib/antlib.xml" />

    <target name="someTask">
        <input message="Enter first argument" addproperty="arg.first" />
        <input message="Enter second argument" addproperty="arg.second" />
        
        <!-- your code here... -->
        <copy file="arg.first" tofile="${arg.second}" />
    </target>
</project>

To run it in batch mode use:

  ant -buildfile run.xml someTask -Darg.first=111.txt -Darg.second=111_copy.txt

Thanx to http://stackoverflow.com/a/14309773