Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I reference another property in a properties file (use ${property}) [duplicate]

Possible Duplicate:
How to reference another property in java.util.Properties?

look at my "file.properties":

key1= My name is key2= ${key1} Martin ! 

Why when I get the value of "key2" my result is "${key1} Martin !" unlike "My name is Martin !"

=> I program in Java 6
=> I use java.util.Properties

like image 839
Martin Magakian Avatar asked Sep 11 '09 17:09

Martin Magakian


People also ask

How use variables in properties file?

The following rules apply to the definition of variables in a properties file: Valid characters in a variable name are uppercase and lowercase letters, numbers 0 - 9, periods, underscores, and hyphens. Variable names are limited to 255 characters. Properties files can exist in a CICS® bundle or an application binding.


2 Answers

You might want look at Apache Configuration,

http://commons.apache.org/configuration/

Among many features it supports is the Variable Interpolation.

like image 169
ZZ Coder Avatar answered Nov 03 '22 06:11

ZZ Coder


What you want to do is impossible using the Java Properties class.

Property keys and values are simply Strings. No processing happens to them, so you can't refer to another value in a value.

like image 39
Thomas Owens Avatar answered Nov 03 '22 06:11

Thomas Owens