I'm aware of reasons for missing or duplicate slf4j implementations on classpath due to (Maven) dependency management and know how to avoid such through exclusions.
However, if I have a multi-module Java project with a JAR containing EJB interfaces and entities, an EJB implementation and a WAR web frontend which is packaged as EAR I do not find a way to place the slf4j API org.slf4j:slf4j-api:1.7.25
, the implementation ch.qos.logback:logback-classic:1.2.3
and the configuration logback.xml
so that I have working logging in the JAR, EJB and WEB module and can avoid both
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
and
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/richter/zpool-tmp/jee-slf4j-logging/jee-slf4j-logging-ear/target/gfdeploy/jee-slf4j-logging-ear/jee-slf4j-logging-web-1.0-SNAPSHOT_war/WEB-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/richter/zpool-tmp/jee-slf4j-logging/jee-slf4j-logging-ear/target/gfdeploy/jee-slf4j-logging-ear/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
and
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/glassfish/web/loader/WebappClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/glassfish/javaee/full/deployment/EarLibClassLoader) for the method's defining class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:418)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
I'm providing a MCVE at https://gitlab.com/krichter/jee-slf4j-logging.
GlassFish 4, no logging framework dependencies is working in pom.xml doesn't cover the Java EE aspect.