6

I recently tried to use Apache Commons-Configuration to manage some local XML configuration files. It drastically falls short on ease of use (can't load empty config files, CombinedConfiguration requires utilization of underlying Configurations for most operations, etc), and consistency across its API (save operation posts no Events, Events are not universal).

Aside from the JDK Preferences which writes to the Registry (which I don't want), are there any other alternatives to managing file based preferences?

Using another file format is not an option.

Spencer Kormos
  • 8,381
  • 3
  • 28
  • 45
  • What's wrong with `Properties`? –  Apr 18 '12 at 18:54
  • Using Properties for XML doesn't provide any benefit over straight properties files, which is not descriptive enough for my purposes. – Spencer Kormos Apr 18 '12 at 20:38
  • 1
    I was referring to straight properties files. Why do you think XML is better suited? –  Apr 18 '12 at 20:57
  • Nestable structure and repeating values. – Spencer Kormos Apr 18 '12 at 21:35
  • Agreed, not being able to create a default config by writing the content of the configuration into a file is a big shortcoming, I am actually currently raging over this issue as well. – siyb Apr 27 '16 at 12:45

2 Answers2

1

I have used XStream in the past for this, but it is just XML data-binding, mapping from file to objects. It puts the burden on you to provide higher level methods (in particular combining configurations, validation).

Christopher Oezbek
  • 23,994
  • 6
  • 61
  • 85
  • I'm starting to think that this is the route I'll need to go (un/marshalling using an XML Api), though I was hoping to avoid it. XStream does make it more simple than others, so I'll try that out first. Thanks for the reminder. – Spencer Kormos Apr 18 '12 at 20:51
  • Good luck. I am in C++ land now, and there is boost::property_tree, which does most of what we want. – Christopher Oezbek Apr 18 '12 at 21:00
0

Your question does not make it clear whether you need to stay with an XML-based technology. If not, then you could do worse than to consider Json, YAML or (my favourite, and the one that I maintain) Config4*.

Ciaran McHale
  • 2,126
  • 14
  • 21