有的时候,我们希望ant中也能类似脚本语言一样进行for循环,以实现一些重复性工作。由于ant核心包并未提供此功能,所以需要下载一个扩展包扔到ant的lib目录下去。详细步骤如下:
1.下载核心包:ant-contrib-1.0b3-bin.zip
2.解压后放到 D:\ant\ant-1.8.2\lib
3.编写build.xml
<?xml version="1.0" encoding="UTF-8"?> <project default="install_package_deploy.start" basedir="."> <property file="ant.properties" /> <target name="loop"> <echo>${file.full.name}</echo> </target> <!-- 把input.deploy.property.paths中的properties文件名循环作为参数传给loop --> <target name="install_package_deploy.start"> <foreach list="" target="loop" param="file.full.name" delimiter=","> <fileset dir="."> <include name="*.properties"/> </fileset> </foreach> </target> <!-- 把list中的数循环传给 screen_number--> <target name="foreach_test"> <foreach list="1,2,3,4,5,6,7" target="screen_number" param="number" delimiter=","> </foreach> </target> <target name="screen_number"> <echo>${number}</echo> </target> </project>
结果: