Jakarta commons configuration Study Notes

Source: Internet
Author: User
Jakarta commons configuration Study Notes

Keywords: Jakarta, commons, Configuration

Runtime Dependencies

Some components required for running:

    • Commons beanutils
    • Commons collections
    • Commons Digester
    • Commons Lang
    • Commons Logging
    • XML APIs or xerces

Dependency:

    1. Core

      • Commons collections
      • Commons Lang
    2. Configurationfactory
      • Commons Logging
      • Commons Digester
    3. Databaseconfiguration
      • Commons Logging
    4. Xmlconfiguration, hierarchicalxml+aion
      • XML APIs or xerces
    5. Jndiconfiguration
      • Commons Logging
    6. Configurationdynabean
      • Commons beanutils
      • Commons Logging
Use configurationfactory for configuration

Portal/
| --Src/
| --WEB-INF/
| ---- Config. xml
| ----Properties/
| ------ Usergui. Properties
| ----Classes/
| ------ Configurationfactorytest. Class

Configurationfactory provides two methods to specify the location of the configuration file:

    • Setconfigurationurl (URL)
    • Setconfigurationfilename (string)

Use the factory. setconfigurationurl (URL) method to specify the configuration file 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 "));

In this case, the declaration of other configuration files in config. xml should be relative to the path of config. xml. <? XML version = "1.0" encoding = "ISO-8859-1"?>
<Configuration>
<PropertiesFilename = "properties/usergui. properties"/>
<! -- OrFilename = "./properties/usergui. properties"-->
</Configuration>

Use the factory. setconfigurationfilename (string) method to specify the configurationfactory factory = new configurationfactory ();
Factory. setconfigurationfilename ("WEB-INF/config. xml ");
Configuration Config = factory. getconfiguration ();
System. Out. println (config. getstring ("Colors. Background "));

In this case, the declaration of other configuration files in config. xml should be relative to the root directory path of the project: <? XML version = "1.0" encoding = "ISO-8859-1"?>
<Configuration>
<PropertiesFilename = "WEB-INF/properties/usergui. properties"/>
</Configuration>

! Note: If the path of the configuration file is incorrect, the following two exceptions will occur:

    • org. Apache. commons. configuration. configurationfactory. getconfiguration (configurationfactory. Java: 135)-exception caught opening stream to URL indicates that config. xml cannot be found
    • Org. apache. commons. digester. digester. endelement (digester. java: 1069)-end event threw exception Java. lang. reflect. invocationtargetexception indicates config cannot be found. other configuration files declared in XML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.