IBM


12.5.3 Step 3: Changing the WAR class loader delegation mode

What if we now wanted the Web module to use the VersionCheckerV1.jar file from the WEB-INF/lib folder? For that task, we would have to change the class loader delegation from parent first to parent last.

Set the delegation mode to PARENT_LAST, using the following steps:

1. Select the Enterprise Applications entry in the navigation area.

2. Select the ClassloaderExample application.

3. Select Manage modules under the Modules section.

4. Select the ClassloaderExampleWeb module.

5. Change the Class loader order to Classes loaded with application class loader first (PARENT_LAST). Remember, this entry should really be called Classes loaded with WAR class loader first, as noted in Class loading/delegation mode.

6. Click OK.

7. Save the configuration.

8. Restart the application.

The VersionCheckerV1 in WEB-INF/lib returns a class version of 1.0. You can see in Example 12-10 that this is the version now used by the WAR file.

Example 12-10 Class loader: Example 3

VersionChecker called from Servlet

VersionChecker is v1.0.

Loaded by com.ibm.ws.classloader.CompoundClassLoader@4d404d40

Local ClassPath: C:\WebSphere\AppServer\profiles\AppSrv02\installedApps\kcgg1d8Node02Cell\ClassloaderExample.ear\ClassloaderExampleWeb.war\WEB-INF\classes;C:\WebSphere\AppServer\profiles\AppSrv02\installedApps\kcgg1d8Node02Cell\ClassloaderExample.ear\ClassloaderExampleWeb.war\WEB-INF\lib\VersionCheckerV1.jar;C:\WebSphere\AppServer\profiles\AppSrv02\installedApps\kcgg1d8Node02Cell\ClassloaderExample.ear\ClassloaderExampleWeb.war

Delegation Mode: PARENT_LAST

VersionChecker called from EJB

VersionChecker is v2.0.

Loaded by com.ibm.ws.classloader.CompoundClassLoader@37f437f4

Local ClassPath: C:\WebSphere\AppServer\profiles\AppSrv02\installedApps\kcgg1d8Node02Cell\ClassloaderExample.ear\ClassloaderExampleEJB.jar;C:\WebSphere\AppServer\profiles\AppSrv02\installedApps\kcgg1d8Node02Cell\ClassloaderExample.ear\VersionCheckerV2.jar

Delegation Mode: PARENT_FIRST 

Tip: Use this to specify that a Web module should use a specific version of a library, such as Struts, or to override classes coming with the WebSphere run time. Put the common version at the top of the hierarchy, and the specialized version in WEB-INF/lib.

The J2EE specification does not provide a standard option to specify the delegation mode in the EAR file, but by using a WebSphere Extended EAR file, you can specify this so you do not have to change it every time you redeploy your application.

If you use the search feature of the Class Loader Viewer to search for *VersionChecker*, you would see the two entries in Figure 12-9.

Figure 12-9 Class Loader Viewer search feature

The screen is too wide to capture, but the code source is shown inExample 12-11.

Example 12-11 Class Loader Viewer search feature

WAS Module Compound Class Loader (WAR class loader):
file: / C: / WebSphere / AppServer / profiles / AppSrv02 / installedApps / kcgg1d8Node02Cell / ClassloaderExample.ear / ClassloaderExampleWeb.war / WEB-INF / lib / VersionCheckerV1.jar

WAS Module Jar Class Loader (Application class loader):
file: / C: / WebSphere / AppServer / profiles / AppSrv02 / installedApps / kcgg1d8Node02Cell / ClassloaderExample.ear / VersionCheckerV2.jar


Redbooks ibm.com/redbooks

Next