passing command line arguments to ant

懵懂的女人 提交于 2019-12-13 12:27:32

问题


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?


回答1:


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




回答2:


This will help you:

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

</target>


来源:https://stackoverflow.com/questions/14309406/passing-command-line-arguments-to-ant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!