Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


Share this Page URL
Help

4.1: Introduction to class loaders > Shared libraries - Pg. 172

Keep the log4j.properties for the Web modules in their original place (/WEB-INF/classes), add log4j.jar to both Web modules (/WEB-INF/lib) and set the class loading mode for the Web modules to Classes loaded with application class loader first (PARENT_LAST). When initializing log4j from a Web module, it loads the log4j.jar from the module itself and log4j would find the log4j.properties on its local classpath, the Web module itself. When the EJB module initializes log4j, it loads from the application class loader and it finds the log4j.properties file on the same class path, the one in the EJB1.jar file. Merge, if possible, all log4j.properties files into one, and place it on the application class loader, in a Resource.jar file, for example. Singletons: The Singleton pattern is used to ensure that a class is instantiated only once. However, once only means once for each class loader. If you have a Singleton being instantiated in two separated Web modules, two separate instances of this class are created, one for each WAR class loader. So in a multi-class loader environment, special care must be taken when implementing Singletons. 4.1.9 Shared libraries