Using JCONFIG to get configuration information in an XML file: Download jconfig in http://sourceforge.net/ download the latest JCONFORGE.NET/Project/ShowFiles.php?group_id=38356&package_id=30463&release_ID = 272653, download the latest bin package (I use jconfig-bin-v2.8.5.zip) Step 2: The required package unwounded the downloaded zip file, there is jconfig.jar in the dist directory (this is a project package) In the lib directory, there is crimson.jar, jaxp.jar, jmxri.jar (this is the three packs required to parse the XML file) to hit these four JARs to your classpath to go to the third step: writing XML configuration files Config.xml XML Version = "1.0" encoding = "ISO-8859-1">
Step 4: Writing Java file public class getconfig {
PUBLIC STATIC Configuration Configuration;
Static {configure = 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);}} fifth Step: Compilation Execution here I only briefly introduce the app, if you are interested, please see the document under the DOCS directory of the ZIP file.