ANT Property Task
Using pre-defined properties :
Below are some pre-defined properties that can be used in the build file directly
| Properties | Description |
|---|---|
| ant.file | Full location of the build file. |
| ant.version | Version of the Apache Ant installation. |
| basedir | The basedir of the build, as specified in the basedir attribute of the project element. |
| ant.java.version | The version of the JDK that is used by Ant. |
| ant.project.name | The name of the project, as specified in the name atrribute of the project element |
| ant.project.default-target | The default target of the current project |
| ant.project.invoked-targets | Comma separated list of the targets that were invoked in the current project |
| ant.core.lib | The full location of the ant jar file |
| ant.home | The home directory of Ant installation |
| ant.library.dir | The home directory for Ant library files - typically ANT_HOME/lib folder. |
Example Build File :
<?xml version="1.0"?> <project name="Hello World Project" default="info"> <target name="info"> <echo>${ant.version}</echo> <echo>${ant.file}</echo> <echo>${basedir}</echo> <echo>${ant.java.version}</echo> <echo>${ant.project.name}</echo> <echo>${ant.project.default-target}</echo> <echo>${ant.project.invoked-targets}</echo> <echo>${ant.core.lib}</echo> <echo>${ant.home}</echo> <echo>${ant.library.dir}</echo> </target> </project>
Running ant on the above build file should produce the following output:
C:\example>ant
Buildfile: C:\example\build.xml
info:
[echo] Apache Ant(TM) version 1.8.3
compiled on February 26 2012
[echo] C:\example\build.xml
[echo] C:\example
[echo] 1.6
[echo] Hello World Project
[echo] info
[echo] info
[echo] C:\Softwares\apache-ant-1.8.3\lib\ant.jar
[echo] C:\Softwares\apache-ant-1.8.3
[echo] C:\Softwares\apache-ant-1.8.3\lib
BUILD SUCCESSFUL
Total time: 0 seconds
C:\example>
Define custom properties :
- If user want to create the custom property task then user can define additional properties using the property element.
- If we need to make build file which contain the different value of property Ant depending on the environment we can use the custom properties.
<?xml version="1.0"?> <project name="Hello World Project" default="info"> <property name="website" value="www.c4learn.com"/> <property name="year" value="2014"/> <target name="info"> <echo>${website}</echo> <echo>${year}</echo> </target> </project>
Output :
C:\example>ant
Buildfile: C:\example\build.xml
info:
[echo] www.c4learn.com
[echo] 2014
BUILD SUCCESSFUL
Total time: 0 seconds
C:\example>
In the above example, we have defined two custom properties i.e website and year using property tag.
