Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...