Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
261 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...