views:

22

answers:

1

Hi,

I have a product built out of multiple processes. Each process uses internally commons configuration.

Does anyone have an idea how to manage the config? I.e. we do not want to duplicate variables so each process will be able to read them.

Additionally, DB solution is no good, as we do not want to be dependent on DB for something like configuration.

Thanks

Yair

A: 

If the configuration is static the simplest solution is to use java.util.Properties. It uses a simple key/value format based on strings, and you can load it from any InputStream / Reader. You just may need to do extra processing for non-string values:

java.util.Properties p = new java.util.Properties();
p.load(new FileReader("myConfiguration.properties"));
int foo = Integer.parseInt(p.getProperty("foo"));
String bar = p.getProperty("bar");

A simple properties file:

foo=13
bar=baz

The javadocs for load(Reader) explains the properties file format.

M. Jessup
This is not what I am looking for. I am using commons configuration. one property file per process. I am looking for a way to manage these multiple files (maybe some how eliminate them) in order to prevent from having multiple duplicate parameters for each process.
YaOg
I have never used commons configuration before, but just took a quick look at the APIs and it seems like it should be possible to use the CompositeConfiguration to extract the common elements to one file, and then have per-process files for the unique properties. As far as eliminating the files I'm not sure what advantage that would provide as you are just moving them somewhere else. The only other thought is to write a program that will generate the per-process files for you, so you still have duplication of config in generated files, but just one source to maintain them.
M. Jessup