I apologize for the title.. i couldn't find a better way to explain the situation.
I use to load properties file using a Property class as described in the URL http://www.exampledepot.com/egs/java.util/Props.html
my question is can I use properties within that properties file ?
example:
test.properties
url.main="http://mysite.com"
url.games={url.main}/games
url.images={url.main}/images
.
.
.
is that possible with some other syntax?
thanks
Apache Commons Configuration provides for this: http://commons.apache.org/configuration/
Simple example code for loading the configuration file:
Configuration config = new PropertiesConfiguration("config.properties");
You can have 'variable interpolated' properties, as described here http://commons.apache.org/configuration/userguide/howto_basicfeatures.html#Variable_Interpolation
application.name = Killer App
application.version = 1.6.2
application.title = ${application.name} ${application.version}
And it also allows you to include other configuration files while you're at it:
include = colors.properties
include = sizes.properties
Besides a whole range of other features.
Never seen that before. You could make your own preprocessor of course. As long as the referenced property occurs before any references to it, you should be able to implement it using some regular expressions/string replacement. But: I would not recommend this method.
Better resolve the duplication by defining different properties:
url.games={url.main}/games
into url.games_extension=/games
url.main
to url.games_extension
to get the full games url in your application code.I wrote my own Configuration library that supports variable expansion in properties files, have a look and see if it provides what you need. An article I wrote to introduce the feature is here.
There is no direct way to substitute the property value within the property file/object but you may replace property value once you read via getProperty()
method. To produce concatenated messages - have a look at MessageFormat class.
String baseValue=prop.getProperty("url.main");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With