有的時候,我們希望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>
結果: