循环遍历ant中的目录结构 [英] Loop through directory structure in ant

查看:29
本文介绍了循环遍历ant中的目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想在不使用 foreach 的情况下遍历 ant 中的目录结构.有没有什么优雅的方法来做同样的事情?

We want to loop through directory structure in ant without using foreach . Is there any elegant way to do the same ?

推荐答案

应用任务 可以遍历一组目录或文件

The apply task can iterate over a set of directories or files

<target name="run-apply">
    <apply executable="echo">
        <dirset dir="src"/>
    </apply>
</target>

我个人喜欢 groovy ANT 任务

<target name="run-groovy">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
    <dirset id="dirs" dir="src"/>
    <groovy>
        project.references.dirs.each {
            ant.echo it
        }
    </groovy>
</target>

任务 jar 的安装很容易自动化:

The installation of the task jar is easily automated:

<target name="install-groovy">
  <mkdir dir="${user.home}/.ant/lib"/>
  <get dest="${user.home}/.ant/lib/groovy-all.jar" src="http://search.maven.org/remotecontent?filepath=org/codehaus/groovy/groovy-all/2.1.1/groovy-all-2.1.1.jar"/>
</target>

最后,如果您通过其他构建文件进行迭代,subant 任务非常有用:

Finally if you're iterating thru other build files, the subant task is very useful:

<target name="run-subant">
    <subant>
        <fileset dir="src" includes="**/build.xml"/>
    </subant>
</target>

这篇关于循环遍历ant中的目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆