12.5.2 Step 2: Adding an EJB module and Utility jar
Next, we decided to add an EJB to our application, which also depends on our VersionChecker JAR file. For this task, we added a VersionCheckerV2.jar file to the root of our EAR. The VersionChecker class in this JAR file returns V2.0. To make it available as a utility JAR on the extensions class loader, we added a reference to it in the EJB module's manifest file.
Example 12-8 Updated MANIFEST.MF for EJB module
Manifest-Version: 1.0 Class-Path: VersionCheckerV2.jar
The result is that we now have a Web module with a servlet in the WEB-INF/classes folder and the VersionCheckerV1.jar file in the WEB-INF/lib folder. We also have an EJB module that references the VersionCheckerV2.jar Utility JAR in the root of the EAR. Which version of the VersionChecker class file would you expect the Web module to load? V1.0 from the WEB-INF/lib or version 2.0 from the Utility JAR?
The test results are then as shown in Example 12-9.
Example 12-9 Class loader: Example 2
VersionChecker called from Servlet VersionChecker is v2.0.
Loaded by com.ibm.ws.classloader.CompoundClassLoader@26282628
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
VersionChecker called from EJB VersionChecker is v2.0.
Loaded by com.ibm.ws.classloader.CompoundClassLoader@26282628
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
As you can see, the VersionChecker is V2.0 when called both from the EJB module and the Web module. The reason is, of course, that the WAR class loader delegates the request to its parent class loader instead of loading it itself, so the Utility JAR is loaded by the same class loader regardless of if it was called from the servlet or the EJB.