当前位置:首页 > 网络编程 > WEB编程 > XML编程 > 用jConfig获取XML文件中的配置信息

用jConfig获取XML文件中的配置信息

点击次数:38 次 发布日期:2008-11-21 22:25:07 作者:源代码网
源代码网推荐

源代码网整理以下第一步:下载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目录下文档。

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华