FileSets are ant's way of creating groups of files to do work on. These files can be found in a directory tree starting in a base directory and are matched by patterns taken from a number of PatternSets and Selectors.

FileSet identifies the base directory tree with its dir attribute. Then the FileSet's enclosed pattern elements, both named (PatternSets) and selected by wildcards (Selectors), choose the files and folders within the base tree.

If any selector within the FileSet do not select a given file, that file is not considered part of the FileSet. This makes FileSets equivalent to an <and> selector container.

Wildcards edit

Wildcards are used by ant to specify groups of files that have a pattern to their names.

  • ? : is used to match any character.
  • * : is used to match zero or more characters.
  • ** : is used to match zero or more directories.

Examples edit

The below FileSets all select the files in directory ${server.src} that are Java source files without "Test" in their name.

<fileset dir="${server.src}" casesensitive="yes">
  <include name="**/*.java"/>
  <exclude name="**/*Test*"/>
</fileset>
<fileset dir="${server.src}" casesensitive="yes">
  <patternset id="non.test.sources">
    <include name="**/*.java"/>
    <exclude name="**/*Test*"/>
  </patternset>
</fileset>
<fileset dir="${client.src}">
 <patternset refid="non.test.sources"/>
</fileset>
<fileset dir="${server.src}" casesensitive="yes">
 <filename name="**/*.java"/>
 <filename name="**/*Test*" negate="true"/>
</fileset>
<fileset dir="${server.src}" casesensitive="yes">
 <filename name="**/*.java"/>
 <not>
   <filename name="**/*Test*"/>
 </not>
</fileset>

Finally edit

FileSets can appear as children of the project element or inside tasks that support this feature.

Next Section, Next Cookbook Chapter