简体   繁体   English

NoClassDefFoundError: org/slf4j/LoggerFactory with logback

[英]NoClassDefFoundError: org/slf4j/LoggerFactory with logback

Please help,请帮忙,

For the past couple of days I have been trying to get Logback 1.1.3 to work with my Bukkit plugin.在过去的几天里,我一直在尝试让Logback 1.1.3与我的 Bukkit 插件一起工作。 For reference my pom.xml includes these lines:作为参考,我的pom.xml包括以下几行:

<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":以下 jars 列在“Maven Dependencies”下:

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

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"); ).服务器控制台生成的堆栈跟踪可以在这里找到(MoneyDrops.java 的第 29 行是: 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.我也搜索过stackoverflow,但所有的答案都表明我需要提供一个使用SLF4J api(例如log4j)的实现,但是,据我所知,logback本身实现了api,我不需要另一个jar文件。

Any help would be greatly appreciated.任何帮助将不胜感激。

There's a dependency in the pom of logback-classic to slf4j which Maven will resolve. logback-classic 的 pom 依赖于 Maven 将解决的 slf4j。 That's the reason of the "appeared out of nowhere".这就是“凭空出现”的原因。

If I read the documentation of JavaPluginLoader it says:如果我阅读 JavaPluginLoader 的文档,它会说:

Represents a Java plugin loader, allowing plugins in the form of .jar代表一个Java插件加载器,允许.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.我对这个库一点也不熟悉,但我会把它解释为“这个插件只会加载指定的 jar”,这将是 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. https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java 中的第 127 行实际上提供了 bukkit 类加载器和一个文件作为类路径。 I presume the file will be your jar.我认为该文件将是您的 jar。

So in order to make this work you'd need to somehow make your dependencies available to the classloader of bukkit.因此,为了完成这项工作,您需要以某种方式使您的依赖项可用于 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. jar 无论如何都是压缩文件,并用您的代码重新打包它们。 This way you can provide a single jar to the pluginloader.通过这种方式,您可以向插件加载器提供单个 jar。 There's a maven plugin doing this for you but I forgot the name.有一个 Maven 插件可以为您执行此操作,但我忘记了名称。

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.我已经得出结论,无论如何我实际上不需要登录我的插件(它不是那么重),并选择完全删除它并依赖Bukkit logger Again, thank you all for your help.再次感谢大家的帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Slf4j 和 Logback 错误:java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory - Slf4j and Logback error: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory java.lang.NoClassDefFoundError: OSGi 中的 org/slf4j/LoggerFactory - java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory in OSGi 休眠-java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - Hibernate - java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 问题 - java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory problem 依赖“ logback-classic”的Maven仍然给出“ java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory”异常 - Maven with dependency on “logback-classic” still gives “java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory” exception 带有 Logback 的 SLF4J:NoClassDefFoundError:org/slf4j/impl/StaticLoggerBinder - SLF4J with Logback: NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder Spring工具套件中的线程“ main”中的异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory in Spring tool suite Gradle-线程“ main”中的异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - Gradle - Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory XUGGLE ERROR:线程“main”中的异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - XUGGLE ERROR: Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 如何解决java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory? - How can I resolve java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM