0

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.

Cong Hui
  • 202
  • 5
  • 16

2 Answers2

2

-cp like all JVM run-options only works if you put it before the name of the class you want to run, or the -jar option if you use that to run the manifested main-class. Any tokens after the classsname or -jar name are passed as arguments to your program. Once you fix that you will find that you need your classpath to contain both the jnetpcap jar and also your class(es), so you need something like

 jar -cp .:path/to/jnetpcap.jar Honey 
 # on Windows use ; instead of :
dave_thompson_085
  • 34,712
  • 6
  • 50
  • 70
1

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

Leo
  • 6,480
  • 4
  • 37
  • 52