passing command line arguments to ant

2019-05-02 01:36发布

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?

2条回答
成全新的幸福
2楼-- · 2019-05-02 02:13

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

查看更多
贼婆χ
3楼-- · 2019-05-02 02:13

This will help you:

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

</target>
查看更多
登录 后发表回答