在Ant中重用不同任务中的文件集合?

时间:2011-06-16 04:34:54

标签: ant build

我在几个目录中有一组文件,我想压缩,然后删除。

fileset似乎需要指定特定目录,看起来patternset s可以重复使用,但我仍然必须拥有多个fileset s(并且它似乎fileset"legacy" datatype)。

files可能就是我所追求的,但我没有办法重用使用它的文件列表。

我希望能够做到这样的事情:

<files id="myfiles" includes="artifacts.jar content.jar 
        /plugins/*.jar /features/*.jar" />

<target name="zip">
    <zip destfile="dest.zip">
        <files ref="myfiles">
    </zip>
</target>

<target name="clean">
    <delete>
        <files ref="myfiles">
    </delete>
</target>

实现这一目标的最简洁方法是什么?

2 个答案:

答案 0 :(得分:1)

路径包含嵌套资源,f.e。文件集

<project default="main">

   <path id="myfiles">
      <fileset dir="/path/to/some/dir">
         <include name="**/*.xml"/>
      </fileset>
      <fileset dir="/path/to/some/other/dir">
         <include name="**/*.xslt"/>
      </fileset>
      <!-- ... -->
   </path>

   <target name="zip">
      <zip destfile="dest.zip">
         <path refid="myfiles"/>
      </zip>
   </target>

   <target name="clean">
      <delete>
         <path refid="myfiles"/>
      </delete>
   </target>

   <target name="main" depends="zip,clean"/>

</project>

答案 1 :(得分:0)

我最终通过让fileset的{​​{1}}成为根并使用dir内的多个include元素来包含特定文件,特别是目录。像这样:

fileset
相关问题