Apache Ant - Property


Properties are key-value-pairs where Apache Ant tries to expand ${key} to value at runtime.

The key name is case-sensitive.


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.


Get / Access

The property name is case-sensitive.


Example in an attribute, for a “builddir” property with the value “build”:

  • In the buildfile
  • At run-time

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.


Build file

<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

<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

Powered by ComboStrap