Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: which configuration framework to use?

I need to decide which configuration framework to use. At the moment I am thinking between using properties files and XML files. My configuration needs to have some primitive grouping, e.g. in XML format would be something like:

<configuration>
    <group name="abc">
        <param1>value1</param1>
        <param2>value2</param2>
    </group>
    <group name="def">
        <param3>value3</param3>
        <param4>value4</param4>
    </group>
</configuration>

or a properties file (something similar to log4j.properties):

group.abc.param1 = value1 
group.abc.param2 = value2

group.def.param3 = value3
group.def.param4 = value4

I need bi-directional (read and write) configuration library/framework. Nice feature would be - that I could read out somehow different configuration groups as different objects, so I could later pass them to different places, e.g. - reading everything what belongs to group "abc" as one object and "def" as another. If that is not possible I can always split single configuration object into smaller ones myself in the application initialization part of course.

Which framework would best fit for me?

like image 343
Laimoncijus Avatar asked Mar 09 '10 09:03

Laimoncijus


2 Answers

Since you are saying that it is possible to also store objects in the config, I would suggest this:

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

like image 183
dimitarvp Avatar answered Sep 29 '22 07:09

dimitarvp


The simplest way to do this would be to use Simple XML. It can bind XML to Java POJOs in a very simple manner. Also, it is much faster than other such XML binding frameworks.

http://simple.sourceforge.net

Only 270K with no dependencies.

like image 23
ng. Avatar answered Sep 29 '22 07:09

ng.