Apache Ant - Property

Card Puncher Data Processing

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

  • 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

<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

See built-in-props





Discover More
Card Puncher Data Processing
Apache Ant - Base Directory (basedir)

The base directory is the directory path from which all path calculations are done. The basedir is define in this order: basedir project attribute basedir property (without the basedir project tag)...
Card Puncher Data Processing
Apache Ant - Flow (Dependency, Condition)

How to control the flow in a build file. Targets can depend on other targets and Apache Ant ensures that these other targets have been executed before. Each target gets executed only once, even...
Card Puncher Data Processing
Apache Ant - Project

A project is the first node of a buildfile A project has: three attributes: name, the name of the project default, the default target to use when no target is supplied. basedir, the base...
Card Puncher Data Processing
Apache Ant - Variable

See
Card Puncher Data Processing
How to develop a Task for Ant?

How to develop a Task for Ant A class is registered as an AnT task if it's provide a method with the signature “public void execute()”. The class doesn't need to extends no superclass and...
Hudson Job Ant Junit
Hudson - Ant Build Steps with Junit Test Call

This article shows you an example on how you can start your junit test with the Ant builder (runner) and Hudson as Scheduler and reporter. An Hudson Job can call an Ant script. Ant can call junit...



Share this page:
Follow us:
Task Runner