Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Ant中重用不同任务中的文件集合?_Ant_Build - Fatal编程技术网

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

在Ant中重用不同任务中的文件集合?,ant,build,Ant,Build,我有一组文件在几个目录,我想压缩,然后删除 filesets似乎需要指定一个特定的dir,而且它看起来像是可以重用的patternsets,但是我仍然需要有多个filesets(而且fileset似乎是一个目录) 文件可能是我想要的,但我看不到使用它重用文件列表的方法 我希望能够做到以下几点: <files id="myfiles" includes="artifacts.jar content.jar /plugins/*.jar /features/*.jar" /&

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

fileset
s似乎需要指定一个特定的dir,而且它看起来像是可以重用的
patternset
s,但是我仍然需要有多个
fileset
s(而且
fileset
似乎是一个目录)

文件
可能是我想要的,但我看不到使用它重用文件列表的方法

我希望能够做到以下几点:

<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>
<fileset dir="." id="fileset.my_files">
    <include name="file1.jar" />
    <include name="dir1/*.jar" />
</fileset>

<target name="build_zip">
    <zip destfile="${dist}/${zip.file}">
        <fileset refid="fileset.my_files" />
    </zip>
</target>

<!-- etc -->


实现这一点最干净的方法是什么?

路径包含嵌套资源,例如文件集

<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>

我最终实现了这一点,将
文件集的
目录作为根目录,并在
文件集中使用多个
include
元素将特定文件包含在特定子目录中。大概是这样的:

<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>
<fileset dir="." id="fileset.my_files">
    <include name="file1.jar" />
    <include name="dir1/*.jar" />
</fileset>

<target name="build_zip">
    <zip destfile="${dist}/${zip.file}">
        <fileset refid="fileset.my_files" />
    </zip>
</target>

<!-- etc -->


这看起来确实有效,但是
zip
任务给了我一个警告
[zip]警告:跳过zip存档C:\temp\521.zip,因为没有包含任何文件。
即使下一行是
[zip]构建zip:C:\temp\521.zip
(并且目标中只有一个zip任务只运行一次)。我会接受这个答案,因为这可能是正确的方法,但我也记录了我的解决方案。“未包含任何文件”表示由于目录为空,模式与任何文件都不匹配,或者必须调整模式以匹配所需的文件。检查模式是否匹配的一个简单方法是使用${toString:pathid}回显路径的内容,或者使用${toString:filesetid}回显文件集的内容。我应该提到,尽管有警告,我指定的文件都包含在zip中。您的环境是什么=Ant版本,OS,Java?我运行的构建脚本来自Eclipse3.6.2(即使用AntEclipse3.6.2的任何版本),运行在IBMJDK6(64位)和Windows7x64上。您是否尝试过您的示例,如果它有效,您使用什么版本的Ant进行了测试?