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

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


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 shipsCONST_2 = sealing waxSomeValue = {CONST_1} and {CONST_2} 

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


Eproperties is the open source project which provides variable substitution along with a few other features - although substitution may arguably be the most useful. It is a subclass of java.util.Properties, and will can be used by any other class that may take configuration information as Properties.


Standard properties files are just key-value pairs. In the text format, Properties just separates key from value and does some simple things such as allowing escaped characters. You might be able to define entities in the verbose XML syntax.

If you want your own substitution syntax, then you can manipulate a returned value as you would with any other string. Alternatively, you could write your own version of Properties or do the substitution when generating the file.