Best Alternatives to Property Files in Java

content-managementjavaproperties

Hey I an working on the product which is live at multiple portals. The product is developed in GWT, JAVA, Hibernate.

My question is : Whether there is any alternative of using property file in java.

My Requirement :

  1. For one property key there are multiple values in live portal for each different portal.

  2. Each time I change property file, I need to make the war again.

  3. The loading of any of the property should not be time-consuming.

Any help or suggession would be apprecialble !!!

Best Answer

I find that JSON files mapped to my own classes does wonders. A few annotations are usually all that's needed to tell the JSON libs how to serialize the class. Outside of this you pretty much live in your code for the rest of the time and get all the benefits of it (refactors, compiler checks, code complete etc).

If you require more strict format and validation of the files then I go for XML by first creating an XSD. Then through JAXB generate the classes, from then on it's the same deal as JSON above. Bit more involved though, only go this route if you require exchanging the data in these files with system that naturally "speak" XML or if you need a strict validation but dont want to spend the time doing it manually.

Yaml can make a pretty good candidate for config. I tried it recently in a python project and I must say it was really nice ! Not sure what the Java yaml work is like though but I would be very surprised if one could not find a good resource to deal with the yaml format.