Configuration parameters may be loaded from the following sources:
XML documents
Windows INI files
Property list files (plist)
JNDI
JDBC Datasource
System properties
Applet parameters
Servlet parameters
Component | Dependencies |
---|---|
Core | Java 1.3 commons-collections commons-lang commons-logging |
ConfigurationFactory | commons-digester commons-beanutils Java 1.4 or xml-apis |
DefaultConfigurationBuilder | commons-beanutils Java 1.4 or (xml-apis + xerces + xalan) |
DatabaseConfiguration | JDBC 3.0 (Java 1.4 or jdbc2_0-stdext.jar) |
XMLConfiguration | Java 1.4 or (xml-apis + xerces + xalan) |
XMLPropertiesConfiguration | Java 1.4 or (xml-apis + xerces) |
PropertyListConfiguration | commons-codec |
XMLPropertyListConfiguration | commons-codec Java 1.4 or xml-apis |
ConfigurationDynaBean | commons-beanutils |
XPathExpressionEngine | commons-jxpath |
EnvironmentConfiguration | Java 1.5 or ant 1.6.5 |
import org.apache.commons.configuration.*;
/**
* Commons Configuration读取属性文件的例子
*
* @author leizhimin 2008-9-23 9:40:17
*/
public class Test1 {
public static void main(String[] args) throws ConfigurationException {
test1();
}
public static void test1() throws ConfigurationException {
CompositeConfiguration config = new CompositeConfiguration();
//config.addConfiguration(new SystemConfiguration());
config.addConfiguration(new PropertiesConfiguration("cfgtest/test1.properties"));
String usernaem = config.getString("username");
String password = config.getString("password");
System.out.println(usernaem + " " + password);
}
}
password = leizhimin
Process finished with exit code 0