Class loader in WebSphere

Home > Search
  by

Let's say you have an identical JAR at two different directories on your WebSphere server.

/usr/share/java/mysql-connector-java-8.0.11.jar

/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/installedApps/DmgrCell01/Delta.ear/Beta.war/WEB-INF/lib/mysql-connector-java-8.0.11.jar

 

You can confirm that both of the JARs are being used by the app by navigating to Troubleshooting Class loader viewer > your app.

 

A JVMs class loader can be used to control which JAR will be used first, and which will be used only if the primary JAR cannot be loaded. First, a shared library that contains the directory where the parent JARs are located will need to be created.

  1. Select Environment.
  2. Select Shared libraries.
  3. Select New.
  4. Give the shared library a name. In the classpath, list the directory where the parent JARs are located.
  5. Select OK.
  6. Select Save.

In this example, a shared library named ParentJARS was created, where the parent JARs reside in the /usr/share/java directory.

 

Create a new class loader.

  1. In the left panel of the WebSphere admin console, select Servers > Server Types > your JVM.
  2. Select Java and Process Management > class loader.
  3. Select New.
  4. Select "Classes loaded with parent class loader first" if you want the parent JAR to be loaded first. Select "Classes loaded with local class loader first (parent last)" if you want the local JAR loaded first. Select OK.
  5. Select Save.

In this example, a class loader with "Classes loaded with parent class loader first" was created.

 

Tied together the class loader and shared library.

  1. Select the newly created class loader.
  2. Select Shared library references.
  3. Select Add.
  4. Select the shared library reference and select OK.
  5. Select Save.

In this example, the class loader was associated with the ParentJARS shared library. You will now restart the JVM for this change to take effect.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments