且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

循环遍历ant中的目录结构

更新时间:2023-09-17 16:19:58

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

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>