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.