RSS Feed for This PostCurrent Article

XML Configuration for Java Program

Download Source Code

Nowadays Java is widely used to code backend program, e.g. running batch job, doing extraction, transaction, and loading, etc. For all the program, the configuration can be in properties file, or XML file. Apache Commons Configuration is used for this purpose. I have written a singleton class which uses Commons Configuration for this purpose.

Below is the sample configuration file

<?xml version=”1.0″ encoding=”ISO-8859-1″ ?>


The code to access the configurations.

AppConfig config = AppConfig.getInstance();

Object obj = config.getProperty(”lists.list”);
if (obj instanceof Collection) {
int size = ((Collection) obj).size();
for (int i = 0; i < size; i++) {
System.out.println(config.getProperty(”lists.list(” + i + “)”));
} else if (obj instanceof String) {

obj = config.getProperty(””);
if (obj instanceof Collection) {
int size = ((Collection) obj).size();
for (int i = 0; i < size; i++) {
System.out.println(config.getProperty(”batch-job.job(” + i + “).name”));
} else if (obj instanceof String) {

Trackback URL

RSS Feed for This Post1 Comment(s)

  1. Wahoo | Oct 6, 2007 | Reply

    Thank you for sharing!

3 Trackback(s)

  1. From Java - Auto Reloading of Configuration File | | Oct 7, 2007
  2. From Develop a Java Plugin Framework | | Oct 7, 2007
  3. From Use JPedal and JBoss Rules for Flexible PDF Extraction | | Oct 16, 2007

RSS Feed for This PostPost a Comment