Reputation: 11
I got trouble in using my external jar file even if I put it inside class path correctly.
My external jar file is in the D:
drive and my class path is "C:\Program Files\Java \jdk1.7.0_51\bin; D:\webcam-capture-0.3.10-RC6.jar; C:\Program Files\Java\jdk1.7.0_51\lib;"
so please help me solve the problem. Below is my code:
import com.github.sarxos.webcam.Webcam;
import javax.swing.JOptionPane;
public class DetectWebcamExample {
public static void main(String[] args) {
try {
Webcam webcam = Webcam.getDefault();
if (webcam != null) {
System.out.println("Webcam: " + webcam.getName());
} else {
System.out.println("No webcam detected");
}
} catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
}
the exeption detail is
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.github.sarxos.webcam.Webcam.<clinit>(Webcam.java:40)
at test.Test.main(Test.java:20)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 2 more
Java Result: 1
i amend the path with "C:\Program Files\Java\jdk1.7.0_51\bin;" and classpath "D:\webcam-capture-0.3.10-RC6.jar;." but the exception is still there
How can I solve this problem?
Upvotes: 1
Views: 500
Reputation: 41271
Java has found com.github.sarxos.webcam.Webcam
so you have successfully added that JAR to the classpath.
What's happening now is that Webcam
is trying to use a log4j
class, and that's not on the classpath.
This is common - package A needs package B; package B needs package C; and you can spend a while finding JARs to fulfil chains of dependencies.
In this case you're going to need two log4j jars - log4j-api and one of a choice of log4j implementation jars. See the log4j web page for details.
If the hunt for dependency jars starts getting silly, consider using Maven or Ivy to handle your dependencies for you.
Upvotes: 1