Meaningless Drivel is fun!*
The moose likes Ant, Maven and Other Build Tools and the fly likes How to get property  based  on runtime value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to get property  based  on runtime value" Watch "How to get property  based  on runtime value" New topic
Author

How to get property based on runtime value

Anil Patel Iii
Greenhorn

Joined: Jun 16, 2013
Posts: 2

Hi- I want to set a property value based on run time value

I tried below and it doesn't work

Sample Build File
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxx
<project name="app">
<property file="build.properties"/>
<target name="test123">

<echo> Start</echo>
<echo>${env}</echo>
<echo> the value ${${env}_hostname}</echo>
<echo>end</echo>

</target>
</project>


build.properties file
dev_hostname=d001
sit_hostname=t005
qa_hostname=t001
ps_hostname=u001
prod_hostname=p001


XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx

C:\test>ant -f build_app.xml test123 -Denv=qa
Buildfile: C:\test\build_app.xml

test123:
[echo] Start
[echo] qa
[echo] the value ${${env}_hostname}
[echo] end

BUILD SUCCESSFUL
Total time: 0 seconds

I want to echo value for qa_hostname t001. I have multiple property values based for env variable ( ie dev_username,dev_password,dev-port).
I also have many build files which uses this property file. I don't want to set the property values inside build.xml

Any input will be appreciated.

Thanks,




Anil Patel Iii
Greenhorn

Joined: Jun 16, 2013
Posts: 2
I got it resolved my self.

To achieve this we have to use propertycopy task in ant-contrib-0.6.jar


 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get property based on runtime value
 
Similar Threads
Configuring Tomcat 7 with Eclipse, Ant
What does ${user.home} means ? Where is build .properties ?
to understand which *.MF to use
I dont quite get some terms in build.xml
Ant Build Failing -- Need a way to pick jar file during run time.