利用jConfig获取xml文件中的配置信息
2008-01-05 19:29:48 来源:WEB开发网利用jConfig获取xml文件中的配置信息
第一步:下载jConfig 在http://sourceforge.net/里下载最新的jConfig项目包http://sourceforge.net/PRoject/showfiles.php?group_id=38356&package_id=30463&release_id=272653,下载最新bin包(我用的是jconfig-bin-v2.8.5.zip)
第二步:所需包 解开下载的zip文件,在dist目录下有jconfig.jar(这是项目包);在lib目录下有crimson.jar,jaXP.jar,jmxri.jar(这是解析xml文件所需的三个包) 把这四个jar打到你的classpath中去
第三步:书写xml配置文件config.xml
<?xml version="1.0" encoding="iso-8859-1" ?>
<properties>
<category name="general">
<property name="QueueConnectionFactory" value="java:/ConnectionFactory"/>
</category>
<category name="database">
<property name="DataSource" value="java:DB2DS"/>
</category>
</properties>
public class GetConfig {
public static Configuration configuration;
static {
configuration = ConfigurationManager.getConfiguration();
}
public static String queueConnectionFactory = getProperties(
"QueueConnectionFactory", "java:/ConnectionFactory");
public static String datasource = getProperties("DataSource", "java:DB2DS",
"database");
public static String getProperties(String key, String defaultValue) {
return configuration.getProperty(key, defaultValue);
}
public static String getProperties(String key, String defaultValue,
String category) {
return configuration.getProperty(key, defaultValue, category);
}
public static void main(String[] args) {
System.out.println(GetConfig.driverClassName + "-" + GetConfig.url +
更多精彩
赞助商链接