ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anderson, Rob (Global Trade)" <>
Subject RE: Token based loading of property files
Date Tue, 12 Jun 2007 17:19:25 GMT
This is possible. Perhaps it would be best to run through an example
that I see on a regular basis.

Here is the scenario:
We have a web application that we need to deploy to several different
environments; localhost, dev, qa, staging and production.

We use a properties file for each environment with the environment
specific values for that environment

So now in the build.xml file I will refer to the ${env}.properties

<fail unless="env">You must specify the environment on the command line.
For example:
ant -Denv=dev deploy

<avialable property="props.file.exists" file="${env}.properties" />

<fail unless="props.file.exists" />

<properties file="${env}.properties" />

So you specify the ${env} property on the command line or you could
prompt for it using the <input> task. This allows you to use the same
properties with different values for each environment that you need to
deploy to. There are also ways to do different things in each
environment. For example, perhaps you need to do something after you
deploy in the production environment. Here is how I would do that:

Line up a number of targets using the depends attribute...

<target name="deploy" depends="package,copyToRemote,unpack,postDeploy"

The targets listed in the depends each do a smaller unit of work:
package - zips up the app locally
copyToRemote - copies the zip file to the remote server using <scp>
unpack - unzips the zip file to the appropriate location on the remote
server using <sshexec>
postDeploy - Does something if needed

So how does postDeploy know what to do? Use a property in the
environmentt file...

The postDeploy target will look like this...\

<target name="postDeploy" if="run.postDeploy" >

The postDeploy target will run if the property ${postDeploy} is defined.
Carefull with this. Note that it does not matter if the propertie is set
to true or false, only that it is defined. In the environments that you
don't want postDeploy to run, do not put the property in the properties
file for that environment.

You can also use the environment properties files to populate values in
configuration files that your application uses. The easiest way to do
this is to put replacement placeholders in the configuration files like



Then use the <replace> task and specify the replacefilterfile attribute
to use your ${env}.properties as the replace filter file.

This is just one example of how you can use one set of properties in
your build file to accommodate the needs of many environments,
configurations, projects, etc.

I hope this helps.

-Rob Anderson

> -----Original Message-----
> From: arijit [] 
> Sent: Tuesday, June 12, 2007 6:21 AM
> To:
> Subject: Re: Token based loading of property files
> in simple words....
> I want to load "" file and use the values 
> stored in this property file to do the following --
> 1. Set some property values for example <property name="location"
> value="?????"/> after reading the value from
> 2. Load few more property files after reading the name of the 
> files to be loaded from
> Any way of achieving this ?
> arijit wrote:
> > 
> > Additionally, since I cannot use name attribute along with file 
> > attribute for property, so although I am loading the 
> property file, by 
> > using <property file="${property_files_location}/"/>  
> > but I cannot refer to that loaded file.
> > 
> > 
> > arijit wrote:
> >> 
> >> <property file="${property_files_location}/"/>
> >> 
> >> <property name="location" value="?????"/>
> >> 
> >> Now have some key-value pair for example
> >> location="C:/test"		
> >> 
> >> Now I want to fill in the value (marked with ?????) with 
> C:/test by 
> >> reading from the file.
> >> 
> >> Is it possible ?
> >> 		
> >> 
> > 
> > 
> --
> View this message in context: 
> 3907149.html#a11078642
> Sent from the Ant - Users mailing list archive at
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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

View raw message