NoClassDefFoundError: org/slf4j/LoggerFactory with logback

狂风中的少年 提交于 2019-12-08 13:54:40

问题


Please help,

For the past couple of days I have been trying to get Logback 1.1.3 to work with my Bukkit plugin. For reference my pom.xml includes these lines:

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>1.1.3</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.1.3</version>
</dependency>

And the following jars are listed under "Maven Dependencies":

  • logback-core-1.1.3.jar
  • logback-classic-1.1.3,jar
  • slf4j-api-1.7.7.jar (which appeared out of nowhere)

The stacktrace that the server console produces can be found here (line 29 of MoneyDrops.java is: private static final Logger LOGGER = LoggerFactory.getLogger("MoneyDropsLogger");).

I have also searched through stackoverflow but all the answers suggest that I need to provide an implementation that use the SLF4J api (such as log4j), however, it is to my understanding that logback natively implements the api and that I do not need another jar file.

Any help would be greatly appreciated.


回答1:


There's a dependency in the pom of logback-classic to slf4j which Maven will resolve. That's the reason of the "appeared out of nowhere".

If I read the documentation of JavaPluginLoader it says:

Represents a Java plugin loader, allowing plugins in the form of .jar

I'm not at all familiar with this library but I would interpret it as "This plugin will only load the specified jar" which would be the MoneyDrops jar.

Line 127 at https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java actually provides the bukkit classloader and a file as the classpath. I presume the file will be your jar.

So in order to make this work you'd need to somehow make your dependencies available to the classloader of bukkit. Maybe the minecraft server?

Another option is to unpack all the dependencies. The jars are compressed files anyway and repack them with your code. This way you can provide a single jar to the pluginloader. There's a maven plugin doing this for you but I forgot the name.




回答2:


Thank you all for your help! I have concluded that I do not actually need logging in my plugin anyway (it is not that heavy) and have opted to remove it completely and rely on the Bukkit logger instead. Again, thank you all for your help.



来源:https://stackoverflow.com/questions/32401726/noclassdeffounderror-org-slf4j-loggerfactory-with-logback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!