Table of Contents


Ant provides an optional task for editing property files. This is very useful when wanting to make unattended modifications to configuration files for application servers and applications. Currently, the task maintains a working property file with the ability to add properties or make changes to existing ones. However, any comments are lost.

PropertyFile Task


Attribute Description Required
file Location of the property file to be edited Yes
comment Header for the file itself no

Parameters specified as nested elements


Use nested <entry> elements to specify actual modifications to the property file itself.

Attribute Description Required
key Name of the property name/value pair Yes
value Value to set (=), to add (+) or subtract (-) At least one must be specified
default Initial value to set for a property if it is not already defined in the property file.
For type date, an additional keyword is allowed: "now"
type Regard the value as : int, date or string (default) No
operation "+" or "=" (default) for all datatypes
"-" (for date and int only).
pattern For int and date type only. If present, Values will be parsed and formatted accordingly. No
unit The unit of the value to be applied to date +/- operations. Valid Values are:
  • millisecond
  • second
  • minute
  • hour
  • day (default)
  • week
  • month
  • year
This only applies to date types using a +/- operation.

The rules used when setting a property value are shown below.  The operation occurs after these rules are considered.



The following changes the file. Assume look like:

# A comment


After running, the file would now look like

#Thu Nov 02 23:41:47 EST 2000


adate=2000/11/02 23\:41

anint=1 17\:34

The slashes conform to the expectations of the Properties class. The file will be stored in a manner so that each character is examined and escaped if necessary. Note that the original comment is now lost. Please keep this in mind when running this task against heavily commented properties files. It may be best to have a commented version in the source tree, copy it to a deployment area, and then run the modifications on the copy. Future versions of PropertyFile will hopefully eliminate this shortcoming.



    comment"My properties">

  <entry  key="akey" value="avalue"/>

  <entry  key="adate" type="date" value="now"/>

  <entry  key="anint" type="int" operation="+"/>

  <entry  key="" type="int" default="0013" operation="+" pattern="0000"/>

  <entry  key="" type="date" value="now" pattern="DDD HH:mm"/>


To produce dates relative from today :



    comment="My properties">

  <entry  key=""

      type="date" default="now" pattern="DDD"

      operation="-" value="1"/>

  <entry  key="formated.tomorrow"

      type="date" default="now" pattern="DDD"

      operation="+" value="1"/>


Concatenation of strings :



    comment="My properties">

  <entry  key="progress" default="" operation="+" value="."/>


Each time called, a "." will be appended to "progress"

Copyright © 2000-2002 Apache Software Foundation. All rights Reserved.