分享

ant-contrib 扩展ant 功能 for、foreach、if

 mjsws 2017-02-11

ant-contrib 扩展ant 功能 for、foreach、if:ant使用for、if等功能,需要下载一个扩展包放到ant的lib目录。

1. 下载扩展包ant-contrib-1.0b3-bin.zip 。

2. 解压后进入目录,有一个ant-contrib-1.0b3.jar,复制到${ant安装目录}/lib 下。

3. 编译脚本,ant -file ${filename} ${targetname} 执行 各个target

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!--?xml version="1.0" encoding="UTF-8" -->
<project basedir="." default="foreachtest">
        <property location="/usr/apache-ant/lib/ant-contrib-1.0b3.jar" name="ant-contrib.jar">
        <taskdef classpath="${ant-contrib.jar}" resource="net/sf/antcontrib/antcontrib.properties">
 
<!-- ################ foreach test ########################## -->
        <target name="loop">
                <echo> ${file.name} </echo>
        </target>
 
        <!-- 把paths中的文件名循环作为参数传给loop -->
        <target name="foreachtesta">
                <foreach delimiter="," list="" param="file.name" target="loop">
                        <path location="./">
                                <fileset dir="." includes="*">
                        </fileset></path>
                </foreach>
        </target>
        <target name="foreachtestc">
                <!-- fileset is deprecated -->
                <foreach delimiter="," list="" param="file.name" target="loop">
                        <fileset dir="." includes="*">
                </fileset></foreach>
        </target>
 
        <!-- 把list中的数循环传给 number-->
        <target name="foreachtestb">
                <foreach delimiter="," list="1,2,3,6,5" param="number" target="number">
                </foreach>
        </target>
 
        <target name="number">
                <echo> ${number} </echo>
        </target>
 
<!-- ################ if test ########################## -->
        <property name="display" value="aa">
        <target name="iftest">
                <if>
                        <equals arg1="aa" arg2="${display}">
                        <then>
                                <echo>aa</echo>
                                <!-- 若符合判断条件,即条件成功,使用antcall命令来执行某个target -->
                                 
                        </antcall></then>
                <elseif>
                        <equals arg1="bb" arg2="${display}">
                        <then>
                                <echo>bb</echo>
                        </then>
                </equals></elseif>
                <else>
                        <echo>else</echo>
                </else>
                </equals></if>
        </target>
 
        <target name="calltarget">
                <echo>call</echo>
        </target>
 
<!-- ################ for test (未解决:failed to create task or type for) ########################### -->
        <target name="fortest">
                <for list="1,2" param="number">
                        <sequential>
                                <!-- <for> makes use of ant's macrodef task, so the @{www.a6qp.com} notation is used for parameter substition -->
                                <echo>@{number}</echo>
                        </sequential>
                        <!-- sequential 循环体,可写多个 -->
                        <sequential>
                                <echo>other@{number}</echo>
                        </sequential>
                </for>
        </target>
</property></taskdef></property></project>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约