Apache Ant Zip Task

Ant Zip task is used to create zip file. basedir attribute is used to refer source of files from where zip file is created. We can use exclude attribute to exclude the file from being zipped.

It makes a implicit fileset and supports various nested elements including <fileset>, <include>, <exclude> and <patternset>.

Apache Ant Zip Task Attributes

AttributeDescriptionRequired
destfileName of zip file to be created.Yes
basedirthe directory from which to zip the files.No
compressStore and compress data as well.No
encodingThe character encoding to use for filenames inside the zip file.No
filesonlyIt is used to store files entries only.No
includesA list of file to be include.No
excludesA list of files that must be excluded.No
updateUpdate the destination file if it is already exists.No
whenemptybehavior when no files match. Valid values are fail, skip, and create.No
duplicatebehavior when a duplicate file is found.No
commentComment to store in the archive.No
levelNon-default level at which file compression should be performed.No
fallbacktoUTF8Whether to use UTF-8 and the language encoding flag instead of the specified encoding.No
zip64ModeWhen to use Zip64 extensions for entries.No

Let's see some examples to create a zipfile.

Apache Ant Zip Task Example

Create a zip file manual.zip by collecting all the files from javatpoin/java directory.

If zip file exist, it update zip file.

We can exclude file by specifying names of files using excludes attribute.





Latest Courses