10

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

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$1.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.

STW
  • 44,917
  • 17
  • 105
  • 161
Kevin
  • 1,080
  • 3
  • 15
  • 41

2 Answers2

10

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.

stacker
  • 68,052
  • 28
  • 140
  • 210
  • The slf4j download has a bunch of .jars. I tried including slf4j-ext-1.6.1.jar and slf4j-simple-1.6.1.jar because they looked the most promising. But I could not tell which was the cannonical slf4j to use. – Kevin Apr 26 '11 at 20:55
  • 3
    I added slf4j-api-1.6.1.jar and slf4j-simple-1.6.1.jar to make it work. – Kevin Apr 26 '11 at 21:01
  • 1
    That first sentence doesn't make sense. It should read that Quartz has a dependency on slf4j. – Robin Apr 26 '11 at 21:08
  • It's clearly using a class lookup. Which means it doesn't directly depend on it. It only depends on it being in the classpath so when the classloader looks for it, it finds it. It didn't need the class so it never tried loading it before, but the Scheduler does calls the ClassLoader and hits hissyfitville. – Tatarize May 23 '13 at 19:46
2

You are going to need the slf4j api jar and an implementation 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.

Robin
  • 24,062
  • 5
  • 49
  • 58