Monday, January 17, 2005

Commons Configuration

Commons Configuration, a Apache project, provides a generic configuration interface which enables an application to read configuration data from a variety of sources. Configuration parameters may be loaded from the following sources:

* Properties files
* XML documents
* JNDI
* JDBC Datasource

The package API is here.

To use this package, some other pachages need to be in the classpath. The list of runtime dependencies are here.


package uhn;

import org.apache.commons.configuration.*;
import java.io.*;

public class Test {

/** Creates a new instance of Test */
public Test() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
// TODO code application logic here
PropertiesConfiguration f = new PropertiesConfiguration("c:\\temp\\test.ini");
f.setProperty("FirstProp.sub", "test1");
f.save();

}

}




package uhn;

import org.apache.commons.configuration.*;
import java.io.*;

public class Test {

/** Creates a new instance of Test */
public Test() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
// TODO code application logic here
XMLConfiguration f = new XMLConfiguration();
f.setProperty("FirstProp", "test1");
f.save("c:\\temp\\test.xml");

}

}

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home