4

When including slf4j-api-1.7.5 and a slf4j logger like simple-1.7.5 in a groovy 2.1.6 project I get the following exception as soon as the first Class instantiating a Logger is loaded:

Caught: java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type taticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory; used in the signature
java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type taticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory; used in the signature
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:299)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
    at Server.<clinit>(Server.java:29)
    at Test.run(Test.groovy:15)

Digging around in the verbose jvm output I found the following lines before the exception was printed:

[Loaded org.slf4j.ILoggerFactory from file:/home/user/.gradle/caches/artifacts-26/filestore/org.slf4j/slf4j-api/1.7.5/jar/6b262da268f8ad9eff941b25503a9198f0a0ac93/slf4j-api-1.7.5.jar]
...
[Loaded org.slf4j.ILoggerFactory from file:/home/user/.gradle/caches/artifacts-26/filestore/org.slf4j/slf4j-api/1.7.5/jar/6b262da268f8ad9eff941b25503a9198f0a0ac93/slf4j-api-1.7.5.jar]

It seems like the Groovy RootLoader AND the Java AppClassLoader try to load the class ILoggerFactory themselves and end up with two "versions" (both of them are probably equal, but the jvm doesn't seem to recognise this). How do I prevent one of these ClassLoaders from loading the ILoggerFactory and finally get logging to work?

4

0 回答 0