Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java properties files, using a key as another keys value, is this possible

Tags:

java

I would like to know if there is any way to use a key as another key's value in .properties files.

For example is this possible, or is there any other way to achieve something similar to this?

key = another_key

app.name=Stack Over Flow  
app.title.welcome=Welcome to {app.name} 

so when i get the value of app.title.welcome it should be "Welcome to Stack Over Flow"

like image 756
Sony Avatar asked Jan 21 '23 00:01

Sony


1 Answers

The Apache Commons Configuration Project has an implementation capable of doing variable interpolation.

Read the section named Variable Interpolation

application.name = Killer App
application.version = 1.6.2
application.title = ${application.name} ${application.version}

You would need this third-party library in your class path, but on the other hand you will not have to worry about writing yet another implementation for this :)

You might like to read the Properties How To as well.

like image 120
Edwin Dalorzo Avatar answered May 13 '23 06:05

Edwin Dalorzo