Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2129

Log4j2 throws NoClassDefFoundError in Java 9

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.10.0, 2.11.0
    • 2.11.0
    • API
    • None
    • Java 9

    Description

      When I execute a sample project (https://github.com/bbucko/log4j2-jpms-sample) in Java 9 a following exception is thrown:

      Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil
      	at org.apache.logging.log4j/org.apache.logging.log4j.status.StatusLogger.<clinit>(StatusLogger.java:71)
      	at org.apache.logging.log4j/org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:60)
      

      Exception is a little bit misleading because it seems that true root cause can be found here:

      java.util.ServiceConfigurationError: org.apache.logging.log4j.util.PropertySource: module org.apache.logging.log4j does not declare `uses`
      	at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:588)
      	at java.base/java.util.ServiceLoader.checkCaller(ServiceLoader.java:574)
      	at java.base/java.util.ServiceLoader.<init>(ServiceLoader.java:503)
      	at java.base/java.util.ServiceLoader.load(ServiceLoader.java:1684)
      	at org.apache.logging.log4j/org.apache.logging.log4j.util.PropertiesUtil$Environment.<init>(PropertiesUtil.java:319)
      	at org.apache.logging.log4j/org.apache.logging.log4j.util.PropertiesUtil$Environment.<init>(PropertiesUtil.java:310)
      	at org.apache.logging.log4j/org.apache.logging.log4j.util.PropertiesUtil.<init>(PropertiesUtil.java:69)
      	at org.apache.logging.log4j/org.apache.logging.log4j.util.PropertiesUtil.<clinit>(PropertiesUtil.java:49)
      	at org.apache.logging.log4j/org.apache.logging.log4j.util.Constants.<clinit>(Constants.java:30)
      	at java.base/java.lang.Class.forName0(Native Method)
      	at java.base/java.lang.Class.forName(Class.java:375)
      	at org.apache.logging.log4j/org.apache.logging.log4j.spi.AbstractLogger.createClassForProperty(AbstractLogger.java:198)
      	at org.apache.logging.log4j/org.apache.logging.log4j.spi.AbstractLogger.<clinit>(AbstractLogger.java:88)
      	at org.apache.logging.log4j/org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:60)
      

      Attachments

        1. log4j-api-patch.jar
          1 kB
          Björn Kautler

        Issue Links

          Activity

            People

              Unassigned Unassigned
              blejzu Blazej
              Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: