About
Properties are key-value-pairs where Apache Ant tries to expand key to value at runtime.
The key name is case-sensitive.
Properties:
- permit to customize a build process
- provide shortcuts for strings
Normally property values can not be changed, once a property is set, most tasks will not allow its value to be modified.
In general properties are of global scope.
Articles Related
Management
Get / Access
The property name is case-sensitive.
${PropertyName}
Example in an attribute, for a “builddir” property with the value “build”:
- In the buildfile
${builddir}/classes.
- At run-time
build/classes.
Where to use a property
Properties may be used in:
- the value of task attributes
- or in the nested text of tasks that support them.
Set
Build file
- in the build file (for example by the property task)
<project name="MyProject" default="dist" basedir=".">
<!-- set global properties -->
<property name="src" location="src"/>
<property file="myPropertyFile.properties" />
<import file="myPropertyFile.xml" />
......
Command line - property
- on the command line. This can be done with the -Dproperty=value option, where property is the name of the property, and value is the value for that property. If you specify a property that is also set in the build file, the value specified on the command line will override the value specified in the build file.
:: Example
ant -f myBuildFile.xml -DpropertyName=value target
Command line Property file
with a property file
ant -f myBuildFile.xml --propertyfile=build.properties
Environment variable
- through environment variable
<property environment="env"/>
<echo message="ANT_HOME is set to = ${env.ANT_HOME}"/>
antrc_pre.bat pre-hook
- through the antrc_pre.bat pre-hook script located
type %HOME%\antrc_pre.bat
echo antrc_pre.bat was called
SET USER=.......
SET PWD=........
Built-in Property
See built-in-props