Skip to content

NoClassDefFoundError for org.apache.logging.log4j.spi.ExtendedLogger in Tomcat 11 with Java 21 #3504

@Dushyant-GitHub

Description

@Dushyant-GitHub

Problem Description

Our web application, which runs in Tomcat 11 and Java 21, uses SLF4J + Logback for logging. However, it allows dynamically importing extensions along with JARs at runtime using the server classloader. One of these extensions depends on log4j-api-2.17.1.jar, which is correctly present in the classpath.

After deploying the extension, calling a service that uses Log4j results in the following error:

java.lang.NoClassDefFoundError: org/apache/logging/log4j/spi/ExtendedLogger

The error mentioned above is being received by executing this line Logger logger = LogManager.getLogger(); in extension service.

However, other Log4j classes, such as LogManager and Logger, are loading without issues.

Environment Details

  • Application Type : WAR-based Java web application

  • Application Server : Apache Tomcat 11

  • Java Version : 21

  • Logging Framework in Main App : SLF4J with Logback

  • Extension Support : Allows dynamic loading of JARs at runtime using the server classloader

  • Problematic Dependency : log4j-api-2.17.1.jar (used by an extension)

Debugging Steps & Findings

  1. Verified that log4j-api-2.17.1.jar is present in the classpath and contains org/apache/logging/log4j/spi/ExtendedLogger.class.
  2. Checked for multiple versions of log4j-api dependency in our application. Result : Only one instance of log4j-api-2.17.1.jar is found.
  3. Printed the class loaders for Log4j classes:
    System.out.println(org.apache.logging.log4j.LogManager.class);
    System.out.println(org.apache.logging.log4j.Logger.class);
    System.out.println(org.apache.logging.log4j.spi.ExtendedLogger.class);  
    

Result:
LogManager and Logger printed correctly.
ExtendedLogger.class throws NoClassDefFoundError.

Additional Notes

  • Same application worked in Tomcat 9 without requiring a restart.

  • Tomcat 11 requires a restart for ExtendedLogger to be found.

  • After restarting Tomcat 11, everything works correctly.

Request for Help

We need guidance on :

  • Why is ExtendedLogger missing, even though other Log4j classes load fine?

  • Does Tomcat 11’s classloader affect Log4j differently compared to Tomcat 9?

  • Are there additional configurations we should try in Tomcat 11?

Would appreciate any insights from the community!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions