<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    風行天下

    JAVA太極
    posts - 4, comments - 10, trackbacks - 0, articles - 55
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    jakarta commons configuration 學習筆記

    Posted on 2005-04-01 10:54 風太少 閱讀(446) 評論(0)  編輯  收藏

    Runtime Dependencies

    運行時需要的一些組件包: 依存關系:
    1. Core
      • commons collections
      • commons lang
    2. ConfigurationFactory
      • commons logging
      • commons digester
    3. DatabaseConfiguration
      • commons logging
    4. XMLConfiguration, HierarchicalXMLConfiguraion
      • xml apis or xerces
    5. JNDIConfiguration
      • commons logging
    6. ConfigurationDynaBean
      • commons beanutils
      • commons logging

    用ConfigurationFactory 進行配置

    portal/
    |--src/
    |--WEB-INF/
    |----config.xml
    |----properties/
    |------usergui.properties
    |----classes/
    |------ConfigurationFactoryTest.class

    ConfigurationFactory 提供了兩種方式用于指定配置文件的位置:
    • setConfigurationURL(URL)
    • setConfigurationFileName(String)
    使用factory.setConfigurationURL(URL) 方法指定配置文件
    ConfigurationFactory factory = new ConfigurationFactory();
    URL url = new File("WEB-INF/config.xml").toURL();
    factory.setConfigurationURL(url);
    Configuration config = factory.getConfiguration();
    System.out.println(config.getString("colors.background"));
    此時config.xml 中其他配置文件的聲明要用相對于config.xml 的路徑
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <configuration>
      <properties fileName="properties/usergui.properties"/>
      <!--或 fileName="./properties/usergui.properties"-->
    </configuration>

    使用factory.setConfigurationFileName(String) 方法指定配置文件
    ConfigurationFactory factory = new ConfigurationFactory();
    factory.setConfigurationFileName("WEB-INF/config.xml");
    Configuration config = factory.getConfiguration();
    System.out.println(config.getString("colors.background"));
    此時config.xml 中其他配置文件的聲明要用相對于項目的根目錄的路徑:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <configuration>
      <properties fileName="WEB-INF/properties/usergui.properties"/>
    </configuration>

    !注:如果配置文件的路徑填寫不正確的話就會遇到如下兩個Exception
    • org.apache.commons.configuration.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:135) - Exception caught opening stream to URL 表明找不到config.xml
    • org.apache.commons.digester.Digester.endElement(Digester.java:1069) - End event threw exception java.lang.reflect.InvocationTargetException 表明找不到config.xml 中聲明的其他配置文件

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲中字慕日产2021| 久久精品国产亚洲AV麻豆不卡| 亚洲国产成人久久精品app| 57pao国产成视频免费播放| 老司机亚洲精品影院| 巨波霸乳在线永久免费视频| 久久久久亚洲AV无码专区体验| 亚洲视频免费在线看| 自拍日韩亚洲一区在线| 成人女人A级毛片免费软件| 亚洲不卡影院午夜在线观看| 色妞WWW精品免费视频| 亚洲精品无码成人片久久不卡 | 女人18毛片免费观看| 亚洲国产精品日韩av不卡在线| 国产无遮挡吃胸膜奶免费看视频| 色偷偷亚洲男人天堂| 久久久青草青青国产亚洲免观 | 亚洲成?v人片天堂网无码| 国产成人高清精品免费观看| 亚洲国产精品乱码一区二区| **毛片免费观看久久精品| 精品亚洲成在人线AV无码| 国产zzjjzzjj视频全免费| 免费看黄的成人APP| 亚洲依依成人精品| 国产成人免费片在线观看 | 2022免费国产精品福利在线| 亚洲av成人无码久久精品| 中文字幕无码免费久久99| 亚洲AV成人精品一区二区三区| 中文字幕久久亚洲一区| 69av免费视频| 国产综合成人亚洲区| 亚洲妇熟XXXX妇色黄| 成人毛片免费观看视频在线| 久久精品成人免费国产片小草| 亚洲狠狠狠一区二区三区| 国产99视频免费精品是看6| 国产精品网站在线观看免费传媒| 亚洲三级在线观看|