Table of Contents

Apache Ant - Property

About

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

The key name is case-sensitive.

Properties:

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.

Management

Get / Access

The property name is case-sensitive.

${PropertyName}

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

${builddir}/classes. 

build/classes.

Where to use a property

Properties may be used in:

Set

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

:: 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

type %HOME%\antrc_pre.bat
echo antrc_pre.bat was called
SET USER=.......
SET PWD=........

Built-in Property

See built-in-props