Search code examples
ant

can we pass command line argument to ant target


How can we pass command line argument to ant target

for example I have target in build.xml defined as below

 <target name="test">
      <echo>Hello,</echo>
   </target>

if I invoke ant as cmd>ant -buildfile build.xml test USERNAME

It should print echo as "Hello, USERNAME"

is it possible some way? Thanks in advance for help


Solution

  • ant -buildfile build.xml test USERNAME would mean run the two targets, test and USERNAME (see Ant manual).

    Instead, do ant -buildfile build.xml -Dname=USERNAME test and

    <target name="test">
        <echo>Hello, ${name}</echo>
    </target>