Class loaders find and load class files. For a deployed application to run properly, the class loaders that affect the application and its modules must be configured so that the application can find the files and resources that it needs. Diagnosing problems with class loaders can be complicated and time-consuming. To diagnose and fix the problems more quickly, use the administrative console Class Load Viewer to examine class loaders and the classes loaded by each class loader.
Before you begin
This article assumes that you have installed an application on a server supported by WebSphere Application Server and you want to examine class loaders used by the application or its modules. The modules can be Web modules (.war files) or enterprise bean (EJB) modules (.jar files). The Class Loader Viewer enables you to examine class loaders in a runtime environment.Why and when to perform this task
The runtime environment of WebSphere Application Server uses the following class loaders to find and load new classes for an application in the following order:
Each class loader is a child of the previous class loader. That is, the application module class loaders are children of the WebSphere extensions class loader, which is a child of the CLASSPATH Java class loader. Whenever a class needs to be loaded, the class loader usually delegates the request to its parent class loader. If none of the parent class loaders can find the class, the original class loader attempts to load the class. Requests can only go to a parent class loader; they cannot go to a child class loader. After a class is loaded by a class loader, any new classes that it tries to load reuse the same class loader or go up the precedence list until the class is found.
If class loaders that affect an application and its modules are not configured properly, the application might not run or an exception might result when deploying or attempting to run the application. Class loading exceptions describes the types of exceptions caused by improperly configured class loaders and suggests ways to use the Class Loader Viewer to correct configurations of class loaders. The types of exceptions include:
The steps that follow describe generally how to use the Class Loader Viewer to examine class loaders and correct problems with application or class loader configurations.
Steps for this task (dependent on configuration)
Click Troubleshooting > Class Loader Viewer to access the Enterprise Applications Topology page.
On the Enterprise Applications Topology page, select a module to access the Class Loader Viewer page. The page lists the class loaders visible to Web and EJB modules in an installed enterprise application. This page helps you to determine which class loaders loaded files of a module and to diagnose problems with class loaders.
The delegation hierarchy is determined by the class loader mode specified for an application or Web module. The mode value can be either Parent First or Parent Last. Refer to the Configure class loaders step for more information.
On the Class Loader Viewer page, click Table View. The Table View page displays the following information:
Class loader attribute | Description |
---|---|
Delegation | Indicates whether the class loader delegates the loading of the module to its parent class loader. A value of true implies that the class loader of the parent application is being used (Parent First). A value of false implies that the module class loader is being used (Parent Last). Refer to the Configure class loaders step for more information. |
Classpath | Lists the paths of .jar files for classes loaded by the class loader. |
Classes | Lists the names of classes loaded in the JVM by this class loader. |
Class loader configuration determines which class loader loads the classes and resource files for an application or Web module. The settings Class loader mode and WAR class loader policy determine which class loader are used.
A Class loader mode value can be either Parent First or Parent Last. The default for an application is Parent First. Thus, the default is to search in the development kit class loaders and WebSphere class loaders before searching in the application class loader to load a class.
To have an application use its class loader, set its Class loader mode to Parent Last on the settings page for an enterprise application An application can override classes contained in a parent class loader, but overriding can result in a ClassCastException or UnsatisfiedLinkError if there is a mixed use of overridden classes and non-overridden classes.
By default, a Web module has its own Web application archive (WAR) class loader to load the contents of the Web module, which are in the WEB-INF/classes and WEB-INF/lib directories. An application class loader is the parent of a WAR class loader. The WAR class loader policy value of an application class loader determines whether the WAR class loader or the application class loader is used to load the contents of the Web module. The default WAR class loader policy value is Module. If the policy is set to Module, then each Web module receives its own class loader whose parent is the application class loader.
To have a Web module use the parent application class loader, set the WAR class loader policy to Application on the settings page of an enterprise application. The application class loader loads the Web module contents as well as the EJB modules, shared libraries, resource adapter archives (.rar files), and dependency .jar files associated to an application.
To have a Web module use its WAR class loader rather than its parent application class loader, set the WAR class loader policy to Module on the settings page of an enterprise application and the Class loader mode to Parent Last on the settings page for a deployed Web module.
What to do next
If you continue to have class loader problems, refer to Class loading exceptions and to Class loading.Related concepts
Class loaders
Related tasks
Class loading
Configuring Web module class loaders
Diagnosing problems (using diagnosis tools)