【问题标题】:Loop over property in Ant循环遍历 Ant 中的属性
【发布时间】:2012-08-27 07:04:48
【问题描述】:

我想了解在 Ant 中以下是可能的

  • 读取属性eg : ${for.loop.condition}

  • 根据上面的属性值,创建一个for循环

  • 并循环从该值动态创建一个字符串

我已经阅读了 ant-contrib task ,但不太确定这是否会对我有所帮助。

任何例子都会帮助我

【问题讨论】:

    标签: ant


    【解决方案1】:

    您可以使用连接一系列值的变量来控制迭代,这样您就可以决定如何处理每个值。检查这个post 它可以帮助你使用“for”标签。

    您还可以使用 for-each 标记来遍历使用文件集标记选择的一组值。

    <foreach target="target2Call" param="paramName">
       <fileset dir="${myDir}">
           <include name="**/mifilesFilter.*" />
       </fileset>
    </foreach>
    

    这里是another example关于如何使用foreach标签。

    【讨论】:

    • 我发现你不能使用混合大小写的参数名称,只有小写对我有用!
    【解决方案2】:

    您好,您可以像这样使用 if 和 for 循环:

    <target name="mTomcat">
      <property name="property" value="xyz"/>                      
      <sequential>
    
      <if>
        <equals arg1="${property}" arg2="xyz" />
        <then>
    
          <for list="${list}" param="param" delimiter=",">
            <sequential>
                < do the stuff here with param >
           </sequential>
         </for>
      </sequential>
    </target>
    

    【讨论】:

    猜你喜欢
    • 2023-01-11
    • 2016-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    • 2014-08-15
    相关资源
    最近更新 更多