手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Xml编程>列表

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

来源: 作者: 时间:2008-03-13
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

第一步:下载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) Www~Chinaz~com

第二步:解开下载的zip文件,在dist目录下有jconfig.jar(这是项目包);在lib目录下有crimson.jar,jaxp.jar,jmxri.jar(这是解析xml文件所需的三个包),把这四个jar打到你的classpath中去。 Www_Chinaz_com

第三步:书写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( Www@Chinaz@com

"QueueConnectionFactory",
"java:/ConnectionFactory");

Www~Chinaz~com

 

public static String datasource
= getProperties("DataSource",
"java:DB2DS",
            "database");
public static String getProperties
(String key, String defaultValue)
{
        return configuration.
  getProperty(key, defaultValue);
    } Chinaz^com

    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);
    } [中国站长站]

} 中国.站.长站

Www_Chinaz_com

第五步:编译执行在这里我只简单介绍应用一下,如有兴趣请查看zip文件的docs目录下文档。 中.国站长站

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!