Bootstrap FreeKB - IBM WebSphere - Classpath and class loader
IBM WebSphere - Classpath and class loader

Updated:   |  IBM WebSphere articles

The classes in a JAR file can be made available to a Java application running in a WebSphere application server in the following ways.

  • The JAR file can be placed in the applications WEB-INF/lib folder
  • The JAR file can be placed in the application servers classpath
  • The JAR file can be placed Shared Library

Placing the JAR file in the applications WEB-INF/lib folder will make it so that classes in the JAR file are only available to the application. In this scenario, the JAR file would be placed in the following directory on the WebSphere server.

/opt/WebSphere/AppServer/profiles/your_profile/installedApps/your_cell/your_ear/your_war/WEB-INF/lib

 


Placing the JAR file in the application servers classpath will make it so that the classes in the JAR file are available to each application running in the application server.

  1. In the left panel of the WebSphere admin console, expand Servers > Server Types > WebSphere application servers.
  2. Select an application server.
  3. Expand Java and Process Management and select Process definition.
  4. Select Java Virtual Machine.
  5. In Classpath, enter the list of JAR files or the list of directories that contain the JAR files you want the WebSphere application server to use.
  6. Select OK.
  7. Select Save.
  8. Restart the application server for this change to take effect.

In this example, the application server is configured to use sample.jar, thus the apps in the application server will be able to use the com/main/people and com/main/places classes.

 


Placing the JAR file in a Shared Library will make it so that the classes in the JAR file are available to each application server that is configured to use the Shared Library.

In the WebSphere admin console, expand Environment and select Shared libraries. Select an appropriate scope. Select New. Give your shared library a name, and in classpath, enter the path to the files being shared, or the path to the directory that contains the files being shared. Select OK. Select Save.

In this example, the JAR files in the /usr/local/jar directory on the WebSphere node servers (not the deployment manager) would be included in the shared library.

 

You can either configure an application server to use a Shared Library, so that all of the applications in the application server can use the files in the Shared Library. Or, you can configure one or more applications to use the Shared Library, so that only certain applications can use the files in the Shared Library.

To configure an application server to use a Shared Library, expand Servers > Server types > your application server > Java and Process ManagementClass Loader > New > Classes loaded with parent loader first or Classes loaded with local class loader first > OK.

Note: "Classes loaded with parent loader first" is the default selection. If the application server is configured with local class loader, then the shared library will be loaded before the local class loader. 

Select the newly created classloader > Shared library references > Add > your Shared Library > OK > SaveRestart the application server for this change to take effect.

 

To configure an application to use a Shared Library, expand Applications > Enterprise applications > Shared library references. From the list of available shared libraries, highlight your shared library, and move the shared library into selected. Select OKRestart the application for this change to take effect.


You can confirm that view the JARs being used by the app in an application server by navigating to Troubleshooting Class loader viewer > your app.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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