views:

113

answers:

5

Can java properties file reference other properties file?

A: 

No. They can't even reference themselves actually. However in the specific application of localization you can use hierarchies of them as ResourceBundles.

EJP
+4  A: 

Well you could certainly have a property in the first file like

secondfile = path/to/another/file

But there is no feature that would automatically import properties at runtime like I think you are asking about - you would need to handle this on your own.

matt b
A: 

You can use Spring to load more then one property file on the spring configuration file(s). So it is easy to reference property on other files "for free"

Anyway be careful because you are adding structural complexity to a flat property file.

daitangio
+1  A: 

Short answer: No, for any value of "reference other properties file".

Longer answer: No, not the way I'd guess want, but there's an ugly hack that lets a property file to include property definitions from other files (if that's what you mean by "referencing").

You can't do it in the classic key=value property file format, but properties can also be written in XML, and XML files can include other XML files, so by extension XML property files can include property definitions from other XML property files. I wouldn't really recommend doing this, though - I'd it breaks the Principle of Least Astonishment - but it's certainly possible.

gustafc
+5  A: 

Commons Configuration supports one property file including the contents of another using the include directive.

Richard Fearn
Nice (+1) (5 more chars needed)
seanizer