Caused By: java.lang.NoClassDefFoundError: org/apache/log4j/Logger

后端 未结 8 1247
醉酒成梦
醉酒成梦 2020-12-02 22:31

I\'ve got an interesting problem in which the org.apache.log4j.Logger class is not found during runtime. I\'m trying to get authorized and that is where it\'s failing:

8条回答
  •  既然无缘
    2020-12-02 22:39

    With the suggestions @jhadesdev and the explanations from others, I've found the issue here.

    After adding the code to see what was visible to the various class loaders I found this:

    All versions of log4j Logger: 
      zip:war/WEB-INF/lib/log4j-1.2.17.jar!/org/apache/log4j/Logger.class
    
    All versions of log4j visible from the classloader of the OAuthAuthorizer class: 
      zip:war/WEB-INF/lib/log4j-1.2.17.jar!/org/apache/log4j/Logger.class
    
    All versions of XMLConfigurator: 
      jar:com.bea.core.bea.opensaml2_1.0.0.0_6-1-0-0.jar!/org/opensaml/xml/XMLConfigurator.class
      zip:war/WEB-INF/lib/ipp-java-aggcat-v1-devkit-1.0.2.jar!/org/opensaml/xml/XMLConfigurator.class
      zip:war/WEB-INF/lib/xmltooling-1.3.1.jar!/org/opensaml/xml/XMLConfigurator.class
    
    All versions of XMLConfigurator visible from the classloader of the OAuthAuthorizer class: 
      jar:com.bea.core.bea.opensaml2_1.0.0.0_6-1-0-0.jar!/org/opensaml/xml/XMLConfigurator.class
      zip:war/WEB-INF/lib/ipp-java-aggcat-v1-devkit-1.0.2.jar!/org/opensaml/xml/XMLConfigurator.class
      zip:war/WEB-INF/lib/xmltooling-1.3.1.jar!/org/opensaml/xml/XMLConfigurator.class
    

    I noticed that another version of XMLConfigurator was possibly getting picked up. I decompiled that class and found this at line 60 (where the error was in the original stack trace) private static final Logger log = Logger.getLogger(XMLConfigurator.class); and that class was importing from org.apache.log4j.Logger!

    So it was this class that was being loaded and used. My fix was to rename the jar file that contained this file as I can't find where I explicitly or indirectly load it. Which may pose a problem when I actually deploy.

    Thanks for all help and the much needed lesson on class loading.

提交回复
热议问题