ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anderson, Rob (Global Trade)" <>
Subject RE: Dynamic references to properties files
Date Mon, 22 May 2006 17:11:12 GMT
You examples below are a little confusing, so forgive me if I am
completely missing the mark with this advice.

My suggestion is to not try to fit all the properties into a single
file. Try creating a properties file for each environment.

Then in your build.xml you can load the appropriate properties file
based on the value of another property, like ${env} for example.

<property file="${env}.properties"/>
<!-- make sure the user set the env property when running ant -->
<fail unless="env">You must specify the env property on the command
line. For example:
ant -Denv=dev

So based in the value of ${env} you will have a different value for
${webpath}. You can do the same for other environment specific
properties as well.

I hope this helps.

-Rob Anderson

> -----Original Message-----
> From: Sunil Goklani [] 
> Sent: Friday, May 19, 2006 6:06 PM
> To:
> Subject: Dynamic references to properties files
> Hi All,
> I had a question on how I could use two variables to access 
> information from 
> my properties files.  I am trying to build an ant script to generate 
> configuration files for all of my development, qa, and 
> staging environments.
> For example I have the following in a properties file:
> #Configuration for adapterconfig.xml
> adapterconfig.webpath=<property 
> name="webPath">http://localhost:7001/cis-7.6.0</property>
> assem1-adapterconfig.webpath=<property 
> name="webPath"></property>
> assem2-adapterconfig.webpath=<property 
> name="webPath"></property>
> The first property is what developers use and check/label 
> into the cvs.  The 
> other values are what I am supposed to have for my respective 
> environments.
> Suppose I input "-Dset.environment=assem1" as a command line 
> argument.  Is 
> there a way possible for me to access the value of 
> ${assem1-adapterconfig.webpath} with a variable combination of 
> "${${set.environment}-${adapterconfig.webpath}}".
> I tried it like that and I got an error because it was 
> replacing the actual 
> value of "adapterconfig.webpath" before it even got to where 
> I wanted it to.
> Second approach:
> I created a temp property and built out the correct string
> <property name="p-temp" 
> value="${}${set.environment}-adapterconfig.webpath${se
> t.close}"/>
> the and set.close are the ${ and } respectively.  
> However now in my 
> destination file, it actually replaces with: 
> "${assem1-adapterconfig.webpath}" and not the value itself.  
> Is there anyway 
> I can make ant recognize this string as a property?
> Thanks all in advance!
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today 
> - it's FREE! 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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

View raw message