第一步:下载jConfig:在http://sourceforge.net/里下载最新的jConfig项目包 http://sourceforge.net/project/showfiles.php?group_id=38356&package_id=30 463&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>
第四步:书写java文件:
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 +
"-" + GetConfig.user + "-"
+ GetConfig.password);
}
}
第五步:编译执行在这里我只简单介绍应用一下,如有兴趣请查看zip文件的docs目录下文档。