IBM Support

Specifying an order for WEB-INF/lib JAR files in the class path in WebSphere Application Server traditional

Education


Abstract

Java EE does not define a class path order for JAR files found in the WEB-INF/lib directory of an application. Therefore, a proper Java EE application must not have any dependency on the order in which WEB-INF/lib JAR files appear in the class path. However, APAR PI90832 ( available in fix packs 8.5.5.14 and 9.0.0.7) provides a way for you to specify the class path order for WEB-INF/lib JAR files.

Content

 

The order in which JAR files appear in the class path on WebSphere Application Server traditional is dependent on the operating system. So it might come as a surprise to you when you try your application on a new operating system and you discover your application fails because it has a dependency on the order.


The preferred solution to this problem is to modify the application to remove the order dependency. However, that might not be convenient or practical. In APAR PI98032, WebSphere Application Server traditional provided an option to specify the ordering of WEB-INF/lib JARs in the class path. Using this option you can ensure the class path is consistent across operating systems.

Two methods are provided for ordering of WEB-INF/lib JAR files in the class path.

  1. Specify the order explicitly, either by specifying the complete list or by specifying one or more JAR files which have an order dependency.

  2. Specify a custom Java Comparator; a Java class that defines the order. A built-in alphabetical Comparator is provided.


Both methods can be set at the server level (applying to all applications), the application level (applying to all web modules in the application), or at the web module level. The recommended method is to apply the setting in the application. This way, the application does not depend on someone having to provide the setting in the application server configuration. However, in cases where modifying the application is not an option, or if you simply want to do a quick test, applying the setting to the application server is an option. A disadvantage of applying the setting at the server level is that the setting applies to all applications running on the server and therefore might have an unintended effect on another application which also has an order dependency.
 

Explicit ordering

Explicit ordering of WEB-INF/lib JARs in the class path is obtained by providing a list of JAR files to be inserted at the beginning of the class path, or by specifying the complete list of JAR files. Elements in the list must be comma-separated. You only need to specify the JARs that have an order dependency.

Server level

Set the following JVM custom property.

Property name: org.eclipse.jst.j2ee.commonarchivecore.ibm_webinflib_order

value: < list of comma-separated JAR file names >


For example:
org.eclipse.jst.j2ee.commonarchivecore.ibm_webinflib_order = First.jar, Second.jar, Third.jar

Application or module level

Add the following attribute to the MANIFEST.MF of the application or the web module:

Attribute name: IBM_WEBINFLIB_ORDER

value:  < list of comma-separated JAR file names >


For example:

IBM_WEBINFLIB_ORDER : First.jar, Second.jar, Third.jar

Alphabetical ordering

A built-in Comparator class is provided to allow you to order the WEB-INF/lib JAR files alphabetically in the class path.


Server level

To apply the setting at the server level, set the following JVM custom property.


Property name: org.eclipse.jst.j2ee.commonarchivecore.ibm_webinflib_comparator

Value: alpha

Application or module level

Add the following attribute to the MANIFEST.MF of the application or the web module:

Attribute name: IBM_WEBINFLIB_COMPARATOR

Value: alpha

For example:

IBM_WEBINFLIB_COMPARATOR : alpha

Ordering via custom Comparator

Precise ordering of the JAR files can be obtained using a java.util.Comparator class. To use this method of ordering, you must supply a Java class that implements the java.util.Comparator interface. To ensure your Comparator class is loaded, place the class in a JAR file and place the JAR file in folder <WAS_HOME>/lib/ext

Server level


To apply the setting at the server level, set the following JVM custom property. The value is the fully qualified class name of your custom comparator class.

Property name: org.eclipse.jst.j2ee.commonarchivecore.ibm_webinflib_comparator

Example value: my.custom.comparators.CustomComparator

Application or web module level


Add the following attribute to the MANIFEST.MF of the application or the web module. The value is the fully qualified class name of your custom comparator class.:

Attribute name: IBM_WEBINFLIB_COMPARATOR

Example value: my.custom.comparators.CustomComparator


For example:
IBM_WEBINFLIB_COMPARATOR : my.custom.comparators.CustomComparator

Example reverse alphabetical custom Comparator

Suppose you want the order of your WEB-INF/lib JAR files in the class path to be alphabetical but in reverse order.

Step 1. Create and compile the class

package my.custom.comparators;

import java.util.Comparator;

public class ReverseAlphaComparator implements Comparator<String> {
    @Override
    public int compare(String s1, String s2) {
        return (-s1.compareToIgnoreCase(s2));
    }
}

Step 2. Create a JAR file containing the class

This example assumes your class is in

C:\workspace\CustomComparator\bin\my\custom\comparators\ReverseAlphaComparator.class


Use the “jar” command to package the class into a JAR file.

C:\workspace\CustomComparator\bin>jar cvf MyCustomJar.jar my/*
added manifest
adding: my/custom/(in = 0) (out= 0)(stored 0%)
adding: my/custom/comparators/(in = 0) (out= 0)(stored 0%)
adding: my/custom/comparators/ReverseAlphaComparator.class(in = 801) (out= 413)(deflated 48%)


Step 3. Place the JAR file in <WAS_HOME>/lib/ext directory

Step 4. Set Java custom property

Property name: org.eclipse.jst.j2ee.commonarchivecore.ibm_webinflib_comparator

value: my.custom.comparators.ReverseAlphaComparator

Alternatively, update the MANIFEST.MF of the application or the web module.

IBM_WEBINFLIB_COMPARATOR : my.custom.comparators.ReverseAlphaComparator

[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"Component":"","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
13 September 2019

UID

ibm11073768