Please note, this is a STATIC archive of website www.javatpoint.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Javatpoint Logo
Javatpoint Logo

Apache Ant Types

Apache Ant provides rich set of types, some of them are given below. We can use these to deal with data, files, path etc and can also be used as service.

Type Description
ClassFileSet It is used to create Jar with all required classes.
DirSet It groups the directories.
FileList A list of files.
FileSet A group of files.
FileMapper It helps to map source and target file.
FilterSet A group of filters.
PatternSet A group of patterns that are referenced by ids.
Selectors A FileSet element, helps to select elements
TarFileSet It is a special form of a FileSet.
ZipFileSet A set of zip files.

ClassFileSet

ClassFileSet is a special type of FileSet which includes all of the class files upon which the root classes are depend. It is used to create JAR with all the required classes for a particular application.

ClassFileSet are declared by the id value which is then used as reference.

DirSet

A DirSet is a group of directories. It supports <patternset> and it's nested elements <include>, <includesfile>, <exclude>, <excludefiles>. It has various attributes which are given below.

Attribute Description Required
dir It holds root of the directory tree of this DirSet Yes
includes A list of patterns of directories. No
includesfile Name of a file which is to be included. No
excludes A list of patterns of directories that must be excluded. No
excludesfile Name of a file which is to be excluded. No
casesensitive It is used to specify whether case-sensitivity should be applied or not. No
follosymlinks It holds a symbolic link to be followed. No
erroronmissingdir It specifies what happens if the base directory does not exist. No

Apache Ant DirSet Example

This example will group all the directories names classess found inside the apps subdirectory of ${build.dir} and excludes which has test in their name.

FileList

FileList is a list (collection) of files. It can be be used with <concat>, <dependset> tasks. FileList is useful for specifying files that may or may not exists. It has attributes given below.

Attribute Description Required
dir It is used to hold base directory of this list. Yes
files List of file names Yes

FileList Example

FileSet

FileSet is a group of files from a single root directory. It collects files based on patternsets specified by Ant. The <include> and <exclude> elements are called patternsets. A patternset is a collection of file matching patterns. By default these are casesensitive, but can be disabled by setting casesensitive = false.

File Set has attributes which are given below.

Attribute Description Required
dir It holds root directory the FileSet. Either dir or file must be specified.
file For specifying a single-file fileset. Either dir or file must be specified.
includes A list of patterns of files that must be included. No
includesfile A file name. No
excludes A list of patterns of files that must be excluded. No
excludesfiles A File name pattern. No
casesensitive Both the include and exclude patterns are casesensitive. No
followsymlinks The symbolic links should be followed. No

Lets see an example and copy files from one directory to another.

FileSet Example

// build.xml

The above code will copy all the java files from dir2 to dir1.

FileMapper

Sometimes after executing a task, the source file and the output both are different and then not be mapped. Apache Ant uses FileMapper to map source and created target file. An instance of org.apache.tools.ant.util.FileNameMapper class and <mapper> element is used to map the files.

The mapper has the following attributes.

Attribute Description Required
type specifies one of the built-in implementations. No
classname specifies the implementation by class name. Exactly one of these.
classpath the classpath to use when looking up classname. No
classpathref Apache Ant? User Manual No
from the from attribute for the given implementation. Depends on implementation
to the to attribute for the given implementation. Depends on implementation

All built-in mappers are case-sensitivity.

Mapper Example

FilterSet

FilterSet is a group of filters and used by two major operations (tasks) copy and move. It uses id and refid attributes, id is used to define a FilterSet and refid is used to refer another FilterSet.

It is also possible to nest FilterSet into FilterSet to get a set union of the contained filters.

It has various attributes which are given below.

Fileset Attributes

Attribute Description Default Required
begintoken It is a string marking the beginning of a token. @ No
endtoken It is a string marking the end of a token. @ No
filtersfile It specifies a single filtersfile. None No
recurse Used for searched more tokens. true No
onmissingfiltersfile It Indicates behavior when a nonexistent filtersfile is specified. fail No

Here, we are copying the abc.txt file to the dist directory from the build directory but wish to replace the token @[email protected] with today's date.

FilterSet Example






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA