Configure Web module class loaders

 

Configure Web module class loaders

You can set values that control the class-loading behavior of an installed Web module.

This article assumes that you have installed a Web module on an application server. See Installing application files for more information.

Configure the class-loader mode value of an installed Web module. 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. If the policy is set to Application on the enterprise application settings page, then the application class loader loads the Web module contents as well as the enterprise bean (EJB) modules, shared libraries, resource adapter archives (RAR files), and dependency Java archive (JAR) files associated to an application. Thus, the configuration of the parent application class loader affects the WAR class loader.

Use
the administrative console to configure the application and WAR class loaders.

  1. If you have not done so already, configure the application class loader. Settings such as WAR class loader policy , Enable class reloading, and Reloading interval can affect Web module class loading. If WAR class loader policy is set to Module, then the Web module receives its own class loader and the WAR class-loader policy of the Web module defines the mode for a WAR class loader. If the policy is set to Application, then the application class loader loads the Web module contents.

  2. Click Applications > Enterprise Application > application_name > Web modules > Web_module_name to access the Web module deployment settings page.

  3. Specify the class-loader mode for the installed Web module. The Web module class-loader mode specifies whether the class loader searches in the parent application class loader or in the WAR class loader first to load a class. The default is to search in the parent application class loader before searching in the WAR class loader to load a class. Select either of the following values for Class loader mode :

    Option Description
    Parent first Causes the class loader to search in the parent application class loader first to load a class. This is the standard for Development Kit class loaders and WebSphere Application Server class loaders.

    Tip: If classes and resources needed by the Web module cannot be accessed by the application class loader, but can be accessed by the WAR class loader, specify Parent last. If the application class loader cannot find a class, the class loader delegates the request to find the class to its parent, the WebSphere Application Server extensions class loader. If the WebSphere Application Server extensions class loader cannot find the class, the class loader delegates the request to its parent, the bootstrap, extensions, and CLASSPATH class loaders created by the Java virtual machine. Requests can only go to a parent class loader; they cannot go to a child class loader. Thus, if Parent first is specified, the WAR class loader never receives a request to load a class.

    Parent last Causes the class loader to search in the WAR class loader first to load a class. By specifying Parent last, your WAR class loader can override classes contained in the parent application class loader.

    Tip: Specifying the Parent last value might result in LinkageErrors or ClassCastException messages if you have mixed use of overridden classes and non-overridden classes.

  4. Click OK .

 

What to do next

Save the changes to the administrative configuration.


Related concepts
Class loaders

Related tasks
Configuring application class loaders
Class loading

Related reference
Web module deployment settings