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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 05:29:19  来源:igfitidea点击:

Ant - Java - zipfileset - excluding a directory

javaantzip

提问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.zipwith all the files and directories under docs/manualprefixed with docs/userguide in the archive.

这基本上创建了存档,myzip.zip其中所有文件和目录都docs/manual以存档中的 docs/userguide 为前缀。

But I don' want to include all the directories under docs/manualto be copied into the archive, I have a directory called oldunder docs/manualwhich I want to exclude...How to achieve this?

但是我不想包含docs/manual要复制到存档中的所有目录,我有一个名为的目录,我想olddocs/manual该目录下排除...如何实现?

回答by Sean Patrick Floyd

From the ZipFileSet reference page

来自ZipFileSet 参考页面

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