ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "bill/wilandra" <b...@wilandra.com>
Subject RE: Dynamic references to properties files
Date Mon, 22 May 2006 17:57:15 GMT
Isn't env a well known property for retrieving op sys environment vars
(e.g., ${env.MYDIR})? If so, can it ever not be set? If it is always set
then the <fail unless="env"> will never fail regardless of whether the user
sets the env property or not on the command line.

Bill 

-----Original Message-----
From: Anderson, Rob (Global Trade) [mailto:Rob.Anderson@nike.com] 
Sent: Monday, May 22, 2006 10:11 AM
To: Ant Users List
Subject: RE: Dynamic references to properties files

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. 

dev.properties
===============
webpath=http://localhost:7001/cis-7.6.0

qa.properties
=============
webpath=http://some-server.com:8185/cis-7.6.0

staging.properties
==============
webpath=http://some-server2.com:8185/cis-7.6.0

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

build.xml
===========
...
<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
</fail>

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 [mailto:upsidedowne@hotmail.com]
> Sent: Friday, May 19, 2006 6:06 PM
> To: user@ant.apache.org
> 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">http://some-server.com:8185/cis-7.6.0</property>
> assem2-adapterconfig.webpath=<property
> name="webPath">http://some-server2.com:8185/cis-7.6.0</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.open}${set.environment}-adapterconfig.webpath${se
> t.close}"/>
> the set.open 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! 
> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional 
> commands, e-mail: user-help@ant.apache.org
> 
> 
> 


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





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


Mime
View raw message