设置 Quartz 时的 java ClassNotFoundException LoggerFactory

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5796193/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 12:47:45  来源:igfitidea点击:

java ClassNotFoundException LoggerFactory when setting Quartz up

javaclasspathquartz-schedulerclassnotfoundexception

提问by Kevin

So I'm using the Quartz jar: quartz-all-2.0.1.jar. From the readme, that jar is supposed to have everything set up. However, when I try to create a SchedulerFactory using

所以我使用 Quartz jar:quartz-all-2.0.1.jar。从自述文件来看,那个 jar 应该已经设置好了一切。但是,当我尝试使用

SchedulerFactory sf = new StdSchedulerFactory();

I get this:

我明白了:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at org.quartz.impl.StdSchedulerFactory.<init>(StdSchedulerFactory.java:268)
    at WebScraper.Main.main(Main.java:19)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

I'm also confused because Eclipse does not show any errors before I try to run the program. Thanks for any help.

我也很困惑,因为在我尝试运行程序之前 Eclipse 没有显示任何错误。谢谢你的帮助。

回答by stacker

The Simple Logging Facade for Java (SLF4J)documentation lists Quartz as depending on slf4j. You could download slf4j and add it to your classpath. I've no idea why it worked earlier without this issue.

简单的日志门面的Java(SLF4J)的文件列表石英为根据SLF4J。您可以下载 slf4j 并将其添加到您的类路径中。我不知道为什么它在没有这个问题的情况下更早地工作。

回答by Robin

You are going to need the slf4j api jar and an implementation jar.

您将需要 slf4j api jar 和一个实现 jar。

As to why it doesn't complain in eclipse. It is only a runtime dependency. You are not compiling any code that actually uses slf4j, so your code compiles just fine. On the other hand, when you try to run, the code you are dependent on (i.e. Quartz) has a dependency on slf4j that you now have to provide.

至于为什么它在日食中不抱怨。它只是一个运行时依赖项。您没有编译任何实际使用 slf4j 的代码,因此您的代码编译得很好。另一方面,当您尝试运行时,您所依赖的代码(即 Quartz)依赖于您现在必须提供的 slf4j。

回答by Lrrr

For those who are more comfortable with maven you could add this dependency to your POM file:

对于那些更熟悉 maven 的人,您可以将此依赖项添加到您的 POM 文件中:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.5.6</version>
</dependency>

and then add this library to your project dependency.

然后将此库添加到您的项目依赖项中。