Im folgenden Post gibt es einige Java Exception bzgl slf4j/log4j und was benötigt wird um diese zu beseitigen.
Exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
Lösung
Folgende JAR files als libs hinzufügen:
Variante 1:
log4j-over-slf4j-1.7.17.jar
slf4j-api-1.7.17.jar
slf4j-simple-1.7.17.jar
Variant 2:
log4j-1.2-api-2.5.jar
log4j-api-2.5.jar
log4j-core-2.5.jar
slf4j-api-1.7.17.jar
slf4j-log4j12-1.7.17.jar
Hinweis: es funktioniert nur eine der beiden Varianten.
Download slf4j: http://www.slf4j.org/download.html
Download log4j: http://logging.apache.org/log4j/2.x/download.html
Exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager
Verwendet werden bereits:
log4j-1.2-api-2.5.jar
slf4j-log4j12-1.7.17.jar
slf4j-api-1.7.17.jar
Lösung
Die JAR Dateien log4j-api-2.5.jar und log4j-core-2.5.jar ebenfalls einbinden.
log4j-1.2-api-2.5.jar
log4j-api-2.5.jar
log4j-core-2.5.jar
slf4j-api-1.7.17.jar
slf4j-log4j12-1.7.17.jar
Exception
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.
Bereit Benutzte JAR Dateien:
lslf4j-api-1.7.17.jar
log4j-over-slf4j-1.7.17.jar
Lösung
Folgende JAR Datei ebenfalls als libs hinzufügen:
slf4j-simple-1.7.17.jar
Details: http://www.slf4j.org/codes.html#StaticLoggerBinder
Exception
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/christian/workspace/project-xy/src/libs/slf4j-simple-1.7.17.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/christian/workspace/project-xy/src/libs/slf4j-log4j12-1.7.17.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 [org.slf4j.impl.SimpleLoggerFactory]
Lösung
Die Warnung kommt, weil slf4j-log4j12-1.7.17.jar und slf4j-simple-1.7.17.jar eingebunden sind. Die Behebung erfolgt einfach indem eine der Dateien gelöscht wird – z.B. slf4j-log4j12-1.7.17.jar.
log4j-over-slf4j-1.7.17.jar
slf4j-api-1.7.17.jar
slf4j-simple-1.7.17.jar
Exception
SLF4J: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.
SLF4J: See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
Exception in thread "main" java.lang.ExceptionInInitializerError
Lösung
Problem ist das log4j-over-slf4j.jar und slf4j-log4j12.jar zur gleichen Zeit genutzt werden und das z.B. slf4j-simple-1.7.17.jar fehlt – ansonsten würde vorige Warnung erneut auftauchen.
Löschen von slf4j-log4j12.jar und hinzufügen von slf4j-simple-1.7.17.jar.
log4j-over-slf4j-1.7.17.jar
slf4j-api-1.7.17.jar
slf4j-simple-1.7.17.jar