无法加载类"org.slf4j.impl.StaticLoggerBinder" - 哪个类路径?

Wit*_*eld 20 slf4j

pom.xml只包含一个对SLF4J的引用:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>1.5.10</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

SLF4J:无法加载类"org.slf4j.impl.StaticLoggerBinder".

SLF4J:默认为无操作(NOP)记录器实现SLF4J:

有关更多详细信息,请参见http://www.slf4j.org/codes.html#StaticLoggerBinder.

我检查了那个URL,实际上它提供了一个解决方案:"放置一个(只有一个)slf4j-nop.jar,slf4j-simple.jar,slf4j-log4j12.jar,slf4j-jdk14.jar或logback-classic.jar on 类路径应该解决问题."

我的问题是:哪个类路径?

  • 系统的%CLASSPATH%?(我没有!我需要专门为此创建它)
  • Eclipse的项目.classpath?(我想我试过这个,但没有帮助)
  • 其他?

我发现相当一些关于这个问题的帖子在这里对SO,但他们都引用同样的答案:"地方......在类路径 ".

哪个类路径?

Kon*_*tis 17

首先,为了添加SLF4J,你应该在你的pom.xml中放置一个且只有一个依赖项.这取决于您选择使用的实施方式.您在pom.xml中添加的每个依赖项都会自动添加到类路径中.只要您使用Eclipse,就不需要修改系统的%CLASSPATH%?

<dependency>
   <groupId>ch.qos.logback</groupId>
   <artifactId>logback-classic</artifactId>
   <version></version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-simple</artifactId>
   <version></version>
   <scope>compile</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
   <version></version>
   <scope>compile</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-jdk14</artifactId>
   <version></version>
   <scope>compile</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

最后但并非最不重要的是,您将收到错误SLF4J:无法加载类"org.slf4j.impl.StaticLoggerBinder".

当使用捆绑的maven版本(m2e)时,Eclipse Juno和Indigo不会抑制消息SLF4J:无法加载类"org.slf4j.impl.StaticLoggerBinder".此行为存在于m2e版本1.1.0.20120530-0009及之后.

虽然,这表示为错误,您的日志将正常保存.在修复此错误之前,突出显示的错误仍然存​​在.有关m2e支持网站的更多信息.

为了抑制此消息,当前可用的解决方案是使用外部maven版本而不是捆绑的Eclipse版本.您可以在下面的问题中找到有关此错误的此解决方案和更多详细信息.

SLF4J:无法加载类"org.slf4j.impl.StaticLoggerBinder".错误

  • 谢谢你这个优秀的答案.首先,它回答了我的问题*"哪个类路径?"*(不需要关注m2e的支持站点建议,因为`slf4j-jdk14`已经在`pom.xml`中引用了?).其次,[这个答案]中的第3步(http://stackoverflow.com/a/12373375/1864054)(你提供的链接)摆脱了错误信息:`Window`>`Preferences`>`Maven`>`安装`>取消选中`Embedded`> Add ...`External`. (3认同)