如何有条件地在Ant中包含一个zipfileset

时间:2017-06-10 18:52:18

标签: ant fileset

在Ant zip任务中,如何有条件地添加zipfileset

我试过这个:

<zip destfile="/path/bar.zip">
    <zipfileset src="foo.zip" if="include.foo.zip">
    </zipfileset>
    ...
</zip>

zipfileset不支持if

2 个答案:

答案 0 :(得分:0)

您需要按documentation

中所述包含命名空间

示例:

<project name="demo" default="build" xmlns:if="ant:if" xmlns:unless="ant:unless">

  <target name="build">

    <zip destfile="bar.zip">
      <zipfileset src="foo.zip" if:true="include.foo.zip">
      </zipfileset>
      ..
      ..
    </zip>
  </target>

</project>

答案 1 :(得分:0)

您应该在Ant类路径中包含ant-contrib jar并使用任务def

<project name="MyProject" basedir="." default="build" xmlns:if="ant:if" xmlns:unless="ant:unless">
        <taskdef resource="net/sf/antcontrib/antcontrib.properties" />

        <target name="build">
            <echo file="salt">it's essential</echo>
            <echo file="chili">Not always</echo>

            <var name="canIncludeChili" value="false" />

            <zip destfile="meal.zip">
                <zipfileset prefix="meal" file="salt" />
                <zipfileset prefix="meal" file="chili" if:true="${canIncludeChili}" />
            </zip>
        </target>

    </project>