Using Jconfig to get configuration information in an XML file

Source: Internet
Author: User
Tags key net return string zip
Xml

The first step: Download jconfig: Download the latest Jconfig project package in http://sourceforge.net/ http://sourceforge.net/project/ showfiles.php?group_id=38356&package_id=30 463&release_id=272653, download the latest bin package ( I'm using a jconfig-bin-v2.8.5.zip.

Step two: Unlock the downloaded zip file, Jconfig.jar (this is a project package) in the Dist directory, and Crimson.jar,jaxp.jar,jmxri.jar in the Lib directory (this is the three packages required to parse the XML file). Hit the four jars into your classpath.

Step three: Write the XML configuration file 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>
       
        

Fourth step: Writing Java files:

 
        
          public class G      Etconfig{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");p ublic static string ge    Tproperties (string key, String defaultvalue) {return Configuration.getproperty (key, DefaultValue); public static string GetProperties (string key, String defaultvalue, String category) {return configuration.getprope    Rty (Key, DefaultValue, category);  }public static void Main (string[] args) {System.out.println (Getconfig.driverclassname + "-" + Getconfig.url + "-" +    Getconfig.user + "-" + Getconfig.password); }}
      
        

Fifth step: Compile execution Here I simply introduce the application, if interested please check the zip file docs directory below.



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.