May 25, 2021 Apache Ant
Ant provides some predefined data types. Don't confuse the term "data types" with the data types that are available in the programming language, but think of them as a set of services that are already configured in the product.
The following data types are provided by Apache Ant.
The data type of the file set represents a collection of files. It is used as a filter to include or remove files that match a pattern.
For example, refer to the following code. Here, the src property points to the source folder of the project.
The file set selects all the .java in the source folder, except those that contain the word 'Stub'. Case-sensitive filters are applied to the file set, which means that files .java Samplestub will not be excluded from the file set.
<fileset dir="${src}" casesensitive="yes">
<include name="/.java"/>
<exclude name="/Stub"/>
</fileset>
A pattern collection refers to a pattern that makes it easy to filter files or folders. Patterns can be created using the meta-characters described below.
The following example demonstrates the use of pattern collections.
<patternset id="java.files.without.stubs">
<include name="src//.java"/>
<exclude name="src//Stub"/>
</patternset>
The pattern collection can be reused with a file set similar to the following:
<fileset dir="${src}" casesensitive="yes">
<patternset refid="java.files.without.stubs"/>
</fileset>
File list data types are similar to file sets, except for the following:
Let's look at an example of a file list data type below. In this example, the property webapp.src.folder points to the source folder of the web app in the project.
<filelist id="config.files" dir="${webapp.src.folder}">
<file name="applicationConfig.xml"/>
<file name="faces-config.xml"/>
<file name="web.xml"/>
<file name="portlet.xml"/>
</filelist>
Using a filter collection data type and copy task, you can replace some text that matches the pattern with a replacement value in all files.
A common example is an appended version number to a released document with the following code:
<copy todir="${output.dir}">
<fileset dir="${releasenotes.dir}" includes="/.txt"/>
<filterset>
<filter token="VERSION" value="${current.version}"/>
</filterset>
</copy>
In this code:
Path data types are often used to represent a class path. T he paths are separated by a sign or colon. However, these characters are replaced at runtime with path separators that execute the system.
The class path is set to a list of jar files and class files in the project, as shown in the following example:
<path id="build.classpath.jar">
<pathelement path="${env.J2EE_HOME}/${j2ee.jar}"/>
<fileset dir="lib">
<include name="*
/.jar"/>
</fileset>
</path>
In this code: