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

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

java - using properties within the properties file

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

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...