Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference another property in java.util.Properties?

Can Java properties file reference other properties file?

## define a default directory for Input files   dir.default=/home/data/in/  dir.proj1=${dir.default}p1 dir.proj2=${dir.default}p2 dir.proj3=${dir.default}p3 

Is this possible?

like image 971
yli Avatar asked May 16 '09 11:05

yli


People also ask

Can I reference another property in a properties file?

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

How do you combine Properties in Java?

First, we create a Properties object to hold all our merged properties. Next, we loop over the Properties objects we are going to merge. We then call the stringPropertyNames() method to get a set of property names. Then we loop through all the property names and get the property value for each name.


1 Answers

Chris Mair's XProperties class may be a good starting point.

You can substitute a constant anywhere in the property value, and even have more than one constant within a value, as in the following example:

CONST_1 = shoes and ships CONST_2 = sealing wax SomeValue = {CONST_1} and {CONST_2}  

In this example, the "SomeValue" property evaluates to "shoes and ships and sealing wax."

like image 76
OscarRyz Avatar answered Sep 20 '22 14:09

OscarRyz