Ant - Java - zipfileset - 不包括目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4245550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ant - Java - zipfileset - excluding a directory
提问by Johnbabu Koppolu
I have an ant target for creating zip like this -
我有一个像这样创建 zip 的蚂蚁目标 -
<zip destfile="${dist}/myzip.zip">
<zipfileset dir="docs/manual" prefix="docs/userguide"/>
</zip>
This basically creates archive myzip.zip
with all the files and directories under docs/manual
prefixed with docs/userguide in the archive.
这基本上创建了存档,myzip.zip
其中所有文件和目录都docs/manual
以存档中的 docs/userguide 为前缀。
But I don' want to include all the directories under docs/manual
to be copied into the archive,
I have a directory called old
under docs/manual
which I want to exclude...How to achieve this?
但是我不想包含docs/manual
要复制到存档中的所有目录,我有一个名为的目录,我想old
在docs/manual
该目录下排除...如何实现?
回答by Sean Patrick Floyd
From the ZipFileSet reference page
<zipfileset>
supports all attributes of<fileset>
in addition to those listed below.
<zipfileset>
支持<fileset>
除了下面列出的那些属性之外的所有属性。
So see FileSetfor reference.
所以请参阅FileSet以供参考。
This is how you do it:
这是你如何做到的:
<zipfileset dir="docs/manual" prefix="docs/userguide">
<exclude name="old/**"/>
</zipfileset>
or inline as attribute:
或内联作为属性:
<zipfileset dir="docs/manual" prefix="docs/userguide" exclude="old/**" />
Update:Using wildcards now instead of simple name.
更新:现在使用通配符而不是简单的名称。
回答by carfieldba
you can exclude an entire directory by this:
您可以通过以下方式排除整个目录:
<zipfileset dir="docs/manual" prefix="docs/userguide" exlcudes="**/old/**"/>
回答by PeterMmm
<zip destfile="${dist}/myzip.zip" excludes="docs/manual/old/**">
<zipfileset dir="docs/manual" prefix="docs/userguide"/>
</zip>
回答by Eli
This was the only one that worked for me for removal of specific file pattern
这是唯一对我有用的删除特定文件模式的方法
<zip destfile="${bin.dir}/boo.jar">
<zipfileset dir="${classes.dir}" excludes="**/*/BooCreator*.class"/>
</zip>