IBM Websphere Classloading set to PARENT_LAST

The main responsibility of class loaders is to find and load the classes[1]. What do we get to do with this. First I’d like to explain the first terms. In class loading we have;

  • PARENT_LAST: Allows us to use the jars that we provide,
  • PARENT_FIRST: Uses existing jars provided by the WAS.

How does this help us? Well if you are using different jar stack than IBM provides, like JSF library in my case, then you will have some troubles with it. In our project our stack was JSF 2.2 Mojarra and Primefaces 6.0 with JDK 1.8. This option can be found All Applications > APPLICATION > Class loader.

However, this option is global setting. If your project EAR, contains multiple WAR files and context and some of them shall be excluded from this operation. Well you can also set class loading separately on the WAS console

All Applications > APPLICATION > Manage Modules > MODULE.war

I assume that the disadvantage of setting the class loading on the console is not permanent, every time you need to make this setting. However, there is an alternative way to set the class loading in a class way during the deployment. In my example I’ll show an EAR having 2 modules, one of them the JSF project will have the class loading set as PARENT_LAST and the other project as a default setting will have the PARENT_FIRST option. The target project is a maven multiple module project [2] [3]. We will succeed this operation by using a deployment.xml file in the EAR project.

Parent pom.xml

The version of the jsf project is kept here, I’ll explain the main reason further.

<properties>
    <supporttool.version>1.0.0</supporttool.version>
</properties>

Ear project pom.xml

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>WINS</artifactId>
    <groupId>PACKAGENAME</groupId>
    <version>18.0-SNAPSHOT</version>
  </parent>
  <artifactId>WinsEar</artifactId>
  <packaging>ear</packaging>
  <name>WinsEar</name>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.5</version>
        <configuration>
          <generateApplicationXml>true</generateApplicationXml>
          <version>5</version>
          <modules>
            <webModule>
              <groupId>PACKAGENAME</groupId>
              <artifactId>WebClient</artifactId>
              <contextRoot>/wins</contextRoot>
            </webModule>
            <webModule>
              <groupId>PACKAGENAME</groupId>
              <artifactId>WINSSupportToolWeb</artifactId>
              <contextRoot>/supporttool</contextRoot>
            </webModule>
          </modules>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>PACKAGENAME</groupId>
      <artifactId>WebClient</artifactId>
      <version>18.0-SNAPSHOT</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>PACKAGENAME</groupId>
      <artifactId>WINSSupportToolWeb</artifactId>
      <version>${supporttool.version}</version>
      <type>war</type>
    </dependency>
  </dependencies>
</project>

Here you don’t have to create an explicit application xml file that has the settings for each project.  In the ear pom, the <generateApplicationXml> tag will create one for you.

Creating path for deployment.xml file

Now this is the very tricky part. You have to create the following path in your EAR project accordingly;

EARPROJECT\src\main\application\META-INF\ibmconfig\cells\defaultCell\applications\defaultApp\deployments\defaultApp

deployment.xml

Now after we are sure that the above folders are created successfully, then we can create our file

<?xml version="1.0" encoding="UTF-8"?>
<appdeployment:Deployment xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:appdeployment="http://www.ibm.com/websphere/appserver/schemas/5.0/appdeployment.xmi" xmi:id="Deployment_1495796489455">
  <deployedObject xmi:type="appdeployment:ApplicationDeployment" xmi:id="ApplicationDeployment_1495796489455" startingWeight="100">
    <modules xmi:type="appdeployment:WebModuleDeployment" startingWeight="10000" uri="WINSSupportToolWeb-1.0.0.war" classloaderMode="PARENT_LAST"/>
<!-- To set the classloading level as "PARENT_LAST" for the whole modules, remove the above line and commment out the below line -->
<!--<classloader xmi:id="Classloader_1297859327856" mode="PARENT_LAST"/>-->
  </deployedObject>
</appdeployment:Deployment>

you need to ensure that maven will create the project as it is defined in the detployment.xml file, otherwise it will not work out.

References

  1. https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.iseries.doc/ae/crun_classload.html
  2. https://maven.apache.org/guides/mini/guide-multiple-modules.html
  3. http://maven.apache.org/plugins/maven-eclipse-plugin/reactor.html

Leave a Reply

Your email address will not be published. Required fields are marked *