将命令行参数传递给 ant [英] passing command line arguments to ant
问题描述
我对 ant 比较陌生,在学校我有一个作业来做一个构建文件.我的问题之一是将其名称(或路径)作为 ant 参数的文件复制到/foldercopy".我需要做类似的事情:
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 文件.txt
ant cpfile file.txt
这样蚂蚁就会把file.txt复制到/foldercopy.我在谷歌上搜索了很多,但我只能找到带有-Darg"的东西,但我的老师说这是不正确的.有什么办法吗?
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?
推荐答案
ant
的普通命令行参数被认为是目标名称,所以如果你想将参数传递给你的目标,你需要使用属性,通过 -D
:
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
并在 build.xml 中以 ${file}
的形式访问该值
and access the value as ${file}
inside build.xml
这篇关于将命令行参数传递给 ant的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!