- ANT - Listeners and Loggers
- ANT - Custom Components
- ANT - Using If Else arguments
- ANT - Using Command Line Arguments
- ANT - Using Token
- ANT - Extending Ant
- ANT - JUnit Integration
- ANT - Eclipse Integration
- ANT - Executing Java code
- ANT - Deploying Applications
- ANT - Packaging Applications
- ANT - Create WAR Files
- ANT - Creating JAR files
- ANT - Build Documentation
- ANT - Building Projects
- ANT - Data Types
- ANT - Property Files
- ANT - Property Task
- ANT - Build Files
- ANT - Environment Setup
- ANT - Introduction
- ANT - Home
Apache ANT Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Ant - Using Token Filter
Ant Filter allows to set a token filter for current project. A token is seperated by @ symbol and can be read using properties file as well.
Steps
Step 1 − Define a token using @@.
This is a sample text written in @year@.
Step 2 − Set the filter.
<filter token="year" value="2021"/>
Step 3 − Use the filter. All tasks will replace the occurence of @year@ with 2021.
<copy todir="${dest.dir}" filtering="true"> <fileset dir="${src.dir}"/> </copy>
Filter Task Properties
Following are the key attributes −
Sr.No | Attribute & Description |
---|---|
1 | token the token string without the separator chars (@) |
2 | value the string that should be put to replace the token when the file is copied. |
3 | filtersfile The file from which the filters must be read. This file must be a formatted as a property file. |
Either token and value to be provided or filtersfile to Filter task to work properly.
Example
Create a src folder with text1.txt file with following contents −
This is a sample text written in @year@.
Create build.xml with the following content −
<?xml version="1.0"?> <project name="sample" basedir="." default="copy"> <property name="src.dir" value="src"/> <property name="dest.dir" value="build"/> <target name="copy"> <filter token="year" value="2021"/> <copy todir="${dest.dir}" filtering="true"> <fileset dir="${src.dir}"/> </copy> </target> </project>
Output
Running Ant on the above build file produces the following output −
F: utorialspointant>ant Buildfile: F: utorialspointantuild.xml copy: [copy] Copying 1 file to F: utorialspointantuild BUILD SUCCESSFUL Total time: 1 second F: utorialspointant>
Verify the content of copied file to build folder.
This is a sample text written in 2021.Advertisements