Ant - 为所有子目录运行 Build.xml
我有一个位于顶层的 build.xml,我希望脚本为每个子目录运行一个目标,并将子目录名称作为参数传递给 ANT 目标。
你能帮忙吗?/??
谢谢
I have a build.xml sitting at the top level and I want the script to run a target for each subdirectory and pass in the subdirectory name as a parameter to the ANT target.
Can you help ?/??
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看 subant 任务。从该页面:
Take a look at the subant task. From that page:
这可能是您正在寻找的内容,
请将其作为您的父 build.xml 中的目标之一
this is might be what you looking for,
put this as one of your target in your parent build.xml
如果您想在 ant 构建文件中执行此操作,可以使用 Ant Contrib 的 for task 迭代子目录列表并为每个子目录执行 ant 任务。
我没有测试这段代码,因为没有安装 ant,但它接近我想的你想要做的。
If you would like to do it in ant build file, you could use Ant Contrib's for task to iterate over list of subdirectories and execute ant task for each of them.
I didn't test this code since don't have ant installed, but it is close to what you're trying to do I suppose.
如果我正确地阅读了问题,这可能就是您正在寻找的。
因此,对于您的示例...
当您从 Ant 调用此命令时,您将在命令行中输入:
ant do-all
,您的输出应如下所示:
do-all:
do-first:
[echo] 来自第一个 init 的问候
do-first:
[echo] 来自第二个构建的问候
先做:
[echo] 你好从第三次编译
构建成功
总时间:1 秒
您当然需要确保用作参数的目录名称实际存在,否则构建将失败。
您还可以随时通过将值添加到 build.properties 文件来提供要使用的变量。
If I read the question correctly, this may be what you are looking for instead.
So for your example...
When you are calling this from Ant, you would enter this at the command line:
ant do-all
and your output should look like this:
do-all:
do-first:
[echo] Hello from first init
do-first:
[echo] Hello from second build
do-first:
[echo] Hello from third compile
BUILD SUCCESSFUL
Total time: 1 second
You will of course need to make sure that the directory name that you are using as a param actually exists, or the build will fail.
You can also always feed the variable that you want to use by adding the value to the build.properties file.