Section B.3. Adding Application-Specific Properties to System Properties


B.3. Adding Application-Specific Properties to System Properties

The InitServlet uses SystemPropertiesUtil to add the log4j.log.dir property (that represents the directory that holds the log file) from the log4j.extra.properties to the System Properties. The SystemPropertiesUtil utility looks like Example B-8.

Example B-8. SystemPropertiesUtil.java
 package com.jbossatwork.util; import java.util.*; public class SystemPropertiesUtil {     /**      * Making the default (no arg) constructor private      * ensures that this class cannnot be instantiated.      */     private SystemPropertiesUtil(  ) {  }     public static void addToSystemPropertiesFromPropsFile(String propsFileName) {         Properties props = ResourceLoader.getAsProperties(propsFileName),                    sysProps = System.getProperties(  );         // Add the keys/properties from the application-specific properties  to         // the System Properties.         sysProps.putAll(props);     } } 

The SystemPropertiesUtil's addToSystemPropertiesFromPropsFile( ) method adds the keys/properties from an application-specific properties file to the System Properties. The application-specific properties file MUST reside in a directory listed on the CLASSPATH. The SystemPropertiesUtil uses the ResourceLoader.getAsProperties( ) method to retrieve application-specific properties file from the CLASSPATH. We'll cover the ResourceLoader utility after we show the Log4jConfigurator.

Now that we have the logging infrastructure in place, let's look more closely at the Log4jConfigurator.



JBoss at Work. A Practical Guide
JBoss at Work: A Practical Guide
ISBN: 0596007345
EAN: 2147483647
Year: 2004
Pages: 197

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net