ANT File List
In the previous tutorial we have learnt about the File Set and different pattern sets available in Apache Ant. In this tutorial we will be learning the difference between file list and file set.
ANT File List :
- File list data type in ant is used for creating list of files.
- File list contains the list of files explicitly having the name of the file.
- Unlike File Set, File List does not support the wild card characters.
- File list data type can be applied only to those files which are having existence. File list cannot be applied on the files that may or may not exist yet
Following is an example of the File list data type
<filelist id="config.files" dir="${webapp.src.folder}"> <file name="config.xml"/> <file name="struts.xml"/> <file name="web.xml"/> <file name="mashup.xml"/> </filelist>
Attributes in FileList :
Attribute | Description | Required |
dir | The base directory of this FileList. | Yes |
files | The list of file names. This is a list of file name separated by whitespace, or by commas. | Yes, unless there is a nested file element |
Different Ways of writing Ant File List :
We can write the File list using below style. File names are separated by comma.
<filelist id = "configfiles" dir = "${doc.src}" files = "config.xml,web.xml"/>
We can also use space or new line for showing file list.
<filelist id = "configfiles" dir = "${doc.src}" files = "config.xml web.xml"/>
Now suppose we have already defined the file list then we can directly reference the file list using below line -
<filelist refid="configfiles"/>
We can also write the above tags using the separate file tags like this -
<filelist id = "configfiles" dir = "${doc.src}"> <file name="web.xml"/> <file name="config.xml"/> </filelist>