<zipfileset>与ant中的<fileset>

Shu*_*jee 6 ant

ant构建工具提供了两个不同的任务<fileset/><zipfileset/>.根据文档<zipfileset/>,如果我们使用src属性,我们可以从.zip文件中提取文件.

我的问题是,如果我们使用dir属性来选择文件,那么两者之间有什么区别, <zipfileset/><fileset/>.

例如

                <zipfileset dir="conf/Gateway>
                <include name="jndi.properties" />
                </zipfileset>

                                 and

                <fileset dir="conf/Gateway>
                <include name="jndi.properties" />
                </fileset>
Run Code Online (Sandbox Code Playgroud)

Edd*_*die 4

如果您正在构建存档(例如 ZIP、WAR 或 JAR),这两个任务之间的一个有用区别是 azipfileset有一个prefix属性,您可以使用该属性将给定文件重新定位到存档中的不同文件夹中。fileset例如,如果以下内容包含在更大的和元素集中zipfileset

<zipfileset dir="conf/Gateway" prefix="properties">
    <include name="jndi.properties" />
</zipfileset>
Run Code Online (Sandbox Code Playgroud)

那么该文件conf/Gateway/jndi.properties实际上将作为conf/Gateway/properties/jndi.properties. 您可以通过其他方式达到相同的目的,但这有时很有用。

否则,只需使用最适合当前任务的任务即可。