-------- Original Message  --------
Subject: Change property value
From: shaffic <safi...@gmail.com>
To: user@ant.apache.org
Date: Fri Feb 18 2011 14:24:22 GMT+0100 (CET)

> 
> is the any alter method to change the property value which is initializd
> 
> Thanks
> Shaffic

In core ant properties are immutable - for good reasons.
But there are circumstances where property immutability is cumbersome.

solution 1, use some ant plugin :

many people used antcontrib for that purpose, but antcontrib development
has stopped in 2006, i recommend an up-to-date alternative with very
innovative features => flaka [1]

<project xmlns:fl="antlib:it.haefelinger.flaka">
<fl:install-property-handler />

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

<target name="main">
  <fl:let>
    <!-- define a variable -->
    myvariable = 'whatever'
    <!-- define a new property -->
    myproperty := 'somevalue'
    <!-- overwrite existing property -->
    foo        ::= 'baz'
  </fl:let>

  <echo>
  myvariable => #{myvariable}
  myproperty => ${myproperty}
  foo        => ${foo}
  </echo>
  </target>
</project>

solution 2, use some scripting language running in JVM
and make use of ant api. Groovy [2] recommended, because IMO (after
using javascript/rhino and jruby in ant before) groovy has the best
compatibility to java and the <groovy> task is great

<project>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
<property name="foo" value="bar"/>

<target name="main">
 <groovy>
  <!-- define a new property -->
  properties.'myproperty' = 'somevalue'
  <!-- overwrite existing property -->
  properties.'foo' = 'baz'
 </groovy>

  <echo>
  myproperty => ${myproperty}
  foo        => ${foo}
  </echo>
 </target>
</project>


[1] flaka  http://code.google.com/p/flaka/
[2] groovy http://groovy.codehaus.org/


Regards, Gilbert



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to