ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilbert Rebhan <>
Subject Re: how to change the property value at run time
Date Wed, 14 May 2008 19:13:41 GMT schrieb:
> Thanks a lot. I know that JAVA_HOME is not the ANT - property.
> I just wanted to check whether can we change the property value at run time.
> Can we have detail list of different properties that ANT supports.??

Some stuff that might be helpful to get you started ...

1. the builtin properties

use =

<echoproperties prefix="java"/>
<echoproperties prefix="ant"/>


<echoproperties prefix="java" destfile=""/>
<echoproperties prefix="ant" destfile=""/>

to see all java / ant's default properties that are automatically set
for any ant script.

2. properties set via -D ...

as with all java apps you can set propertyvalues with -Dpropertyname=value

f.e. in bla.xml you have

<property name="antlogfile" value="/test/logs/ant.log"/>
<record name="${antlogfile}" action="start"/>
<record name=${antlogfile}" action="stop"/>

when starting ant with
ant -Dantlogfile=/log/ant.log -f mybuild.xml
${antlogfile} holds /log/ant.log
when starting only with
ant -f bla.xml
${antlogfile} holds /test/logs/ant.log

that can be used for defaults

see =

3. the properties set via property /xmlproperty file

you have a file with key=value pattern, f.e.

load the properties in your build.xml

  <property file=""/>

<echo>$${key} == ${key1}${line.separator}$${key2} == ${key2}</echo>

btw. $$ is the masking for a $
${line.separator} is one of those builtin java properties, so
the example gets

${key1} == value
${key2} == anothervalue

4. files set via call to ant api by script or special ant tasks

normally ant properties are immutable once set,
but it's possible to overwrite them with the method
project.setProperty("propertyname", "value") called in an ant task
or with <script> task


<property name="foo" value="bar"/>

<target name="depends">
    <script language="ruby">
      $project.setProperty "foo", "baz"

<target name="main" depends="depends">
      $${foobar} == ${foobar}

guess what's the value of foo ...

You'll find special ant tasks that use the same behaviour in

But beware, this is against normal ant behaviour !
Only recommended for advanced uses and only when you need to.

there's also a method to set a new property
project.setNewProperty("propertyname", "value")
without overwriting some existing property

4. finally a speciality about filesets


<fileset dir="C:/foobar" id="yourID">
  <include name="**/*.xml"/>

the property ${toString:yourID} is automatically set and
holds all files caught by your include pattern in a comma
separated list

you may use that list for further processing, f.e. echoing
to a file, withn <script>, in a task that provides a kind of for loop

in addition = consult the ant manuel and ant user list archives

Regards, Gilbert

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message