Tutorials Navigation
Apache Ant Tutorial - Data Types
Tutorial Name: Apache Ant Tutorial - Data Types
Category: PC Tutorials
Submitted By: hoot
Date Added:
Comments: 0
Views: 528
Related Forum: PC Building Forum
Share:
Ant provides a number of predefined data types. Do not confuse the term "data types" with those that are available in the programming language, instead consider them as a set of services that are built into the product already.
The following data types are provided by Apache Ant.
Fileset
The fileset data types represents a collection of files. It is used as a filter to include or exclude files that match a particular pattern.
For example, refer the following code. Here, the src attribute points to the source folder of the project.
The fileset selects all .java files in the source folder except those contain the word 'Stub'. The case-sensitive filter is applied to the fileset which means a file with the name Samplestub.java will not be excluded from the fileset.
<fileset dir = "${src}" casesensitive = "yes">
<include name = "**/*.java"/>
<exclude name = "**/*Stub*"/>
</fileset>
Pattern set
A pattern set is a pattern that allows to filter files or folders easily based on certain patterns. Patterns can be created using the following meta characters
? Matches one character only.
* Matches zero or many characters.
** Matches zero or many directories recursively.
The following example depicts the usage of a pattern set.
<patternset id = "java.files.without.stubs">
<include name = "src/**/*.java"/>
<exclude name = "src/**/*Stub*"/>
</patternset>
The patternset can then be reused with a fileset as follows
<fileset dir = "${src}" casesensitive = "yes">
<patternset refid = "java.files.without.stubs"/>
</fileset>
File list
The filelist data type is similar to the file set except the following differences
filelist contains explicitly named lists of files and it does not support wild cards.
filelist data type can be applied for existing or non-existing files.
Let us see the following example of the filelist data type. Here, the attribute webapp.src.folder points to the web application source folder of 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>
Filter set
Using a filterset data type along with the copy task, you can replace certain text in all files that matches the pattern with a replacement value.
A common example is to append the version number to the release notes file, as shown in 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
The attribute output.dir points to the output folder of the project.
The attribute releasenotes.dir points to the release notes folder of the project.
The attribute current.version points to the current version folder of the project.
The copy task, as the name suggests, is used to copy files from one location to another.
Path
The path data type is commonly used to represent a class-path. Entries in the path are separated using semicolons or colons. However, these characters are replaced at the run-time by the executing system's path separator character.
The classpath is set to the list of jar files and classes in the project, as shown in the example below.
<path id = "build.classpath.jar">
<pathelement path = "${env.J2EE_HOME}/${j2ee.jar}"/>
<fileset dir = "lib">
<include name = "**/*.jar"/>
</fileset>
</path>
In this code
The attribute env.J2EE_HOME points to the environment variable J2EE_HOME.
The attribute j2ee.jar points to the name of the J2EE jar file in the J2EE base folder.
Ratings
Comments
Related Tutorials
- 01. Emulating Xbox 360 on PC for Running COD4 With Mods(3,526)
- 02. How to: Matrix Numbers | Batch File(1,913)
- 03. How to Password Protect Files on Windows(859)
- 04. How to play Socom 2/3/ and Combined Assault on PC(6,746)
- 05. Modern Warfare 2 Vac Ban Bypass Tutorial(6,169)
- 06. How to embed an image on TheTechGame(3,104)
- 07. [PC] NIOH 2 OTHER USER SAVE RESIGN(13,017)
- 08. Host bot lobbies! Full Tutorial!(11,356)
- 09. Unban yourself [Plutonium BO2](14,262)
- 10. Fall Guys - How to Change Your Name Color on Fall Guys(8,396)
- 11. Best Crosshair Settings for Valorant(6,534)
- 12. Othercide The Surgeon Boss Guide(2,548)
- 13. Othercide Remembrances Unlock Guide(4,476)
- 14. Othercide Beginners Tips and Tricks(2,719)
- 15. How to Fix Grounded Crashes, Loading Time, Low FPS and Other(4,855)
"Apache Ant Tutorial - Data Types" :: Login/Create an Account :: 0 comments