ANT File Set



Ant File Set :

  1. The Fileset refer as a collection of files.
  2. The Fileset is generally used as a filter to include and exclude files that match a particular pattern.

Sample Example:

<fileset dir="${src}" casesensitive="yes">
  <include name="**/*.java"/>
  <exclude name="**/*Order*"/>
</fileset>

Explanation of Build Script :

  1. The src attribute written in fileset element points to the source folder of the project.
  2. The fileset selects all java files in the source folder but all the java files containing the word ‘Order’ will be excluded
  3. The filter applied to the fileset is case sensitive so file with the name Processorder.java will not be excluded from the fileset

Examples of Ant FileSet :

Example 1 :

<fileset dir="${src}" casesensitive="yes">
  <include name="**/*.java"/>
  <exclude name="**/*Test*"/>
</fileset>

All the files from ‘src’ folder having extension ‘.java’ will be included in the file set excluding the files having word ‘Test’ in their name.

Different FileSet Attributes :

AttributeDescriptionRequired
dirthe root of the directory tree of this FileSet
fileshortcut for specifying a single-file fileset
defaultexcludesindicates whether default excludes should be used or not (yes | no); default excludes are used when omitted.No
includescomma- or space-separated list of patterns of files that must be included; all files are included when omitted.No
includesfilethe name of a file; each line of this file is taken to be an include pattern.No
excludescomma- or space-separated list of patterns of files that must be excluded; no files (except default excludes) are excluded when omitted.No
excludesfilethe name of a file; each line of this file is taken to be an exclude pattern.No
casesensitiveMust the include and exclude patterns be treated in a case sensitive way? Defaults to true.No
followsymlinksShall symbolic links be followed? Defaults to true. See the note below.No
erroronmissingdirSpecify what happens if the base directory does not exist. If true a build error will happen, if false, the fileset will be ignored/empty. Defaults to true. Since Apache Ant 1.7.1 (default is true for backward compatibility reasons.)No