Apache Ant Jar

JAR is a group of Java classes and known as Java Archive file. In Ant, we can create Jar files by using <jar> element in build.xml file.

It is a task and implicitly use FileSet and supports it?s attributes. It also allows to various nested elements like <include>, <exclude>, <patternset> etc and contains attributes which are given below.

Apache Ant Jar Attributes

AttributeDescriptionRequired
destfileThe JAR file to create.Yes
basedirThe directory from which to jar the files.No
compressStore and compress data.No
filesonlyIt is used to store only file entries.No
includesA list of patterns of files that must be included while creating Jar.No
excludesA list of patterns of files that must be excluded while creating Jar.No
updateIndicates whether to update Jar or not.No
duplicatebehavior when a duplicate file is found. Valid values are add, preserve, and fail.No
levelNon-default level at which file compression should be performed.No
useLanguageEncodingFlagWhether to set the language encoding flag if the encoding is UTF-8.No
createUnicodeExtraFieldsWhether to create Unicode extra fields to store the file names a second time inside the entry's metadata.No
fallbacktoUTF8Whether to use UTF-8 and the language encoding flag instead of the specified encoding.No
flattenAttributesWhether to merge attributes occurring more than once in a section.No
zip64ModeWhen to use Zip64 extensions for entries.No

JAR Example

Jar all files in the ${build}/classes directory into a file called app.jar in the ${dist}/lib directory. <jar destfile="${dist}/lib/app.jar" basedir="${build}/classes"/>





Latest Courses