Search code examples
javanoclassdeffounderrorjnetpcap

NoClassDefFoundError with classpath


I'm attempting to run a program using the command:

java Honey -cp ../../jnetpcap-1.3.0/jnetpcap.jar

and am getting the title error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/jnetpcap/Pcap
        at Honey.main(Honey.java:18)
Caused by: java.lang.ClassNotFoundException: org.jnetpcap.Pcap
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 1 more

I would greatly appreciate it if anyone could point out to me what I might be doing wrong.


Solution

  • You must explicitly tell the JVM where is the native library.

    Try something like this

    sudo ../jdk1.8.0_45/bin/java -Djava.library.path=/home/leoks/Downloads/jnetpcap-1.3.0 -cp .:jnetpcap.jar Honey

    I don't know how "Honey" looks like, so I've used this instead

    http://jnetpcap.com/?q=examples/classic

    For this specific example, since it requires some special permissions, I've run it using sudo.

    For this example I've downloaded jnetpcap for ubuntu 64-bit from here

    http://sourceforge.net/projects/jnetpcap/files/jnetpcap/1.3/jnetpcap-1.3.0-1.ubuntu.x86_64.tgz/download

    I've used Oracle JDK 1.8.0_45 and Ubuntu 14.04.2 LTS