【測試技術】ant中的for循環用法


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

 

結果:

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM