WebSphere Tutorial · Traditional WebSphere Application Server · Lesson 18 of 23

Class Loading and Shared Libraries

WebSphere's class loader hierarchy, parent-first and parent-last delegation, shared libraries, and diagnosing NoSuchMethodError and ClassCastException.

Members can save this page, take notes and track progress. See membership · Sign in

The hierarchy

JVM (bootstrap, extensions) → WebSphere runtime → shared libraries → application (EAR) → module (WAR)

With parent-first delegation (the default) a class is looked up in the parents before the application, so a copy of a library in the server or a shared library wins over the one in your WAR. Parent-last reverses that for an application or module.

Symptoms of conflicts

  • NoSuchMethodError / NoClassDefFoundError: an older version of a library was loaded.
  • ClassCastException: X cannot be cast to X: the same class loaded by two class loaders.
  • Works in one environment, fails in another: different shared libraries or server libraries.

Fixing them

Find which JAR the class came from (traditional WAS's Class Loader Viewer, -verbose:class), remove duplicates or align versions, use an isolated shared library when several applications need the same library version, and switch to parent-last only deliberately. Liberty hides server internals from applications by default, which removes many conflicts; configure it with <classloader delegation="parentLast" commonLibraryRef="..."/>.

Which copy of a library wins under each delegation modeTry it yourself
loaders = {
    "server": {"com.fasterxml.jackson.ObjectMapper": "jackson 2.9 (server lib)"},
    "app": {"com.fasterxml.jackson.ObjectMapper": "jackson 2.17 (WEB-INF/lib)",
            "com.acme.Orders": "orders.war"},
}

def load(cls, delegation):
    order = ["server", "app"] if delegation == "parentFirst" else ["app", "server"]
    for loader in order:
        if cls in loaders[loader]:
            return loaders[loader][cls]

for mode in ["parentFirst", "parentLast"]:
    print(f"{mode:11} ObjectMapper from {load('com.fasterxml.jackson.ObjectMapper', mode)}")

Output

parentFirst ObjectMapper from jackson 2.9 (server lib)
parentLast  ObjectMapper from jackson 2.17 (WEB-INF/lib)

Test yourself

With parent-first delegation, which copy of a library is used when both the server and the WAR contain it?

  1. The WAR's copy
  2. The server's copy
  3. The newest one
  4. Neither; it fails
Show answer

Answer: The server's copy

Parents are searched first, so their copy wins.

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake