Reverse the CLASSLOADER order (BEA)Tag(s): Servlet/JSP


By default, Weblogic loads a class by asking the parent classloader to load the required class. This can be a problem, if you have a JAR version in the server LIB directory and your web app requires an another version.

ref : WebLogic Server Application Classloader Overview

To make sure that your web app will use the JAR located in its WEB-INF\LIB, create a file called weblogic.xml in the WEB-INF directory with the content :

<!DOCTYPE weblogic-web-app PUBLIC
    "-//BEA Systems, Inc.//DTD Web Application 8.1//EN"
      "http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd">

<weblogic-web-app>
   <container-descriptor>
      <prefer-web-inf-classes>true</prefer-web-inf-classes>
   </container-descriptor>
</weblogic-web-app>

Another technique is to use a FilteringClassLoader.

The FilteringClassLoader provides a mechanism for you to configure deployment descriptors to explicitly specify that certain packages should always be loaded from the application, rather than being loaded by the system classloader.

To configure the FilteringClassLoader to specify how a certain package is to be loaded, add a prefer-application-packages descriptor element to the weblogic-application.xml

The following example specifies that org.apache.log4j.* is loaded from the application, not the system classloader:

<prefer-application-packages>
  <package-name>org.apache.log4j.*</package-name>
</prefer-application-packages>
ref : http://download.oracle.com/docs/cd/E11035_01/wls100/programming/classloading.html#wp1097187
blog comments powered by Disqus