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. Solution: We use a properties file for each environment with the environment specific values for that environment dev.properties =============== hostname=server222.company.com user=devuser tomcat_home=/usr/local/tomcat_dev webserver_home=/usr/local/apache_dev qa.properties ============== hostname=server222.company.com user=qauser tomcat_home=/usr/local/tomcat_qa webserver_home=/usr/local/apache_qa staging.properties =============== hostname=server223.company.com user=stageuser tomcat_home=/usr/local/tomcat_stage webserver_home=/usr/local/apache_stage So now in the build.xml file I will refer to the ${env}.properties file.... Build.xml ============= ... <fail unless="env">You must specify the environment on the command line. For example: ant -Denv=dev deploy </fail> <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... prod.properties =============== hostname=server225.company.com user=produser tomcat_home=/usr/local/tomcat_prod webserver_home=/usr/local/apache_prod run.postDeploy=true The postDeploy target will look like this...\ <target name="postDeploy" if="run.postDeploy" > ... </taget> 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 this... httpd.conf ============== ... Port=__PORT__ ... dev.properies ============== ... __PORT__=8081 ... 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 [mailto:[EMAIL PROTECTED] > Sent: Tuesday, June 12, 2007 6:21 AM > To: user@ant.apache.org > Subject: Re: Token based loading of property files > > > in simple words.... > > I want to load "abc.properties" 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 abc.properties > > 2. Load few more property files after reading the name of the > files to be loaded from abc.properties > > 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}/abc.properties"/> > > but I cannot refer to that loaded file. > > > > > > arijit wrote: > >> > >> <property file="${property_files_location}/abc.properties"/> > >> > >> <property name="location" value="?????"/> > >> > >> Now abc.properties 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 abc.properties file. > >> > >> Is it possible ? > >> > >> > > > > > > -- > View this message in context: > http://www.nabble.com/Token-based-loading-of-property-files-tf > 3907149.html#a11078642 > Sent from the Ant - Users mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]