André Hincu
André Hincu

Reputation: 427

passing command line arguments to ant

I am relatively new in ant, at school I have an assignment to do a build file. One of my questions is to copy to "/foldercopy" the file whose name(or path) is taken as argument for ant. I need to do something like:

ant cpfile file.txt

So ant will copy the file.txt to /foldercopy. I searched a lot on google but all I could find was something with "-Darg", but my teacher said that it's not correct. Is there any way to do it?

Upvotes: 5

Views: 18039

Answers (2)

SteveScm
SteveScm

Reputation: 575

This will help you:

<target name="copytask" >
  <copy file="file.txt" todir="path-od-dir" failonerror="false" />

</target>

Upvotes: -4

Ian Roberts
Ian Roberts

Reputation: 122424

Plain command line arguments to ant are considered to be target names, so if you want to pass arguments to your target you need to use properties, via -D:

ant -Dfile=file.txt cpfile

and access the value as ${file} inside build.xml

Upvotes: 21

Related Questions