Go to content Go to sidebar

More on the Ant PropertyFile task

A reader writes in, requesting greater control over the behavior of the entry element of the ant PropertyFile Task:

I am having a problem where in, if the number in test.properties is more than 999 then the increment adds a comma. The incremented number after 999 will be 1,000.

The answer is to use the pattern attribute of the entry element:


<project default="run">
  <target name="run">
    <propertyfile file="test.properties">
      <entry key="count" type="int" operation="+" value="1" pattern="0">
    </propertyfile>
  </target>
</project>

With the addition of this attribute, the count property no longer includes the thousands separator:

$ cat test.properties
#Sat Apr 18 20:16:30 GMT 2009
count=999
$ ant
Buildfile: build.xml

run: [propertyfile] Updating property file: test.properties

BUILD SUCCESSFUL Total time: 0 seconds $ cat test.properties #Sat Apr 18 20:29:41 GMT 2009 count=1000