Johnbabu Koppolu
Johnbabu Koppolu

Reputation: 3252

Ant - Java - zipfileset - excluding a directory

I have an ant target for creating zip like this -

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

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?

Upvotes: 7

Views: 19491

Answers (4)

Eli
Eli

Reputation: 768

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>

Upvotes: 0

carfieldba
carfieldba

Reputation: 31

you can exclude an entire directory by this:

<zipfileset dir="docs/manual" prefix="docs/userguide" exlcudes="**/old/**"/>

Upvotes: 3

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 298818

From the ZipFileSet reference page

<zipfileset> supports all attributes of <fileset> in addition to those listed below.

So see FileSet for reference.

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.

Upvotes: 12

PeterMmm
PeterMmm

Reputation: 24630

<zip destfile="${dist}/myzip.zip" excludes="docs/manual/old/**">
    <zipfileset dir="docs/manual" prefix="docs/userguide"/>    
</zip>

Upvotes: 1

Related Questions