jnetpcap – java.lang.UnsatisfiedLinkError:com.slytechs.library.NativeLibrary.dlopen(Ljava / lang / String;)J

我正在使用IntelliJ来运行示例java-jnetpcap应用程序。 我在类路径中有64位JDK并包含以下依赖项

 jnetpcap jnetpcap 1.4.r1425-1f  

我正在运行下面的sample.java类

 public class PcapReaderDemo { private static final String filePath= "/src/main/resources/TAPcapture.pcap"; public static void main(String [] arguments){ final StringBuilder errbuf = new StringBuilder(); Pcap pcap = Pcap.openOffline(filePath,errbuf); if (pcap == null) { System.err.printf("Error while opening device for capture: " + errbuf.toString()); return; } PcapPacketHandler jpacketHandler = new PcapPacketHandler() { public void nextPacket(PcapPacket packet, String user) { System.out.printf("Received at %s caplen=%-4d len=%-4d %s\n", new Date(packet.getCaptureHeader().timestampInMillis()), packet.getCaptureHeader().caplen(), // Length actually captured packet.getCaptureHeader().wirelen(), // Original length user // User supplied object ); } }; System.out.println("Cleared"); } } 

它抛出以下exception:

  PcapReaderDemo Exception in thread "main" java.lang.UnsatisfiedLinkError: com.slytechs.library.NativeLibrary.dlopen(Ljava/lang/String;)J at com.slytechs.library.NativeLibrary.dlopen(Native Method) at com.slytechs.library.NativeLibrary.(Unknown Source) at com.slytechs.library.JNILibrary.(Unknown Source) at com.slytechs.library.JNILibrary.loadLibrary(Unknown Source) at com.slytechs.library.JNILibrary.register(Unknown Source) at com.slytechs.library.JNILibrary.register(Unknown Source) at com.slytechs.library.JNILibrary.register(Unknown Source) at org.jnetpcap.Pcap.(Unknown Source) at com.demo.myapexapp.PcapReaderDemo.main(PcapReaderDemo.java:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) 

请建议您输入错误的地方。

我也遇到了这个exception,发现我忘记了RELEASE_NOTES.txt的安装步骤。

除非将它们放在操作系统的默认位置,否则库将无法找到二进制文件,或者Java会以某种方式找到它们。 对我来说,遵循指示,这个错误消失了。

很难比源材料更好地总结它,所以我将它直接粘贴到这里:

 2) Setup native jnetpcap dynamically loadable library. This varies between operating systems. * On Win32 systems do only one of the following - copy the jnetpcap.dll library file, found at root of jnetpcap's installation directory to one of the window's system folders. This could be \windows or \windows\system32 directory. - add the jNetPcap's installation directory to system PATH variable. This is the same variable used access executables and scripts. - Tell Java VM at startup exactly where to find jnetpcap.dll by setting a java system property 'java.library.path' such as: c:\> java -Djava.library.path=%JNETPCAP_HOME% - You can change working directory into the root of jnetpcap's installation directory. * On unix based systems, use one of the following - add /usr/lib directory to LD_LIBRARY_PATH variable as java JRE does not look in this directory by default - Tell Java VM at startup exactly where to find jnetpcap.dll by setting a java system property 'java.library.path' such as: shell > java -Djava.library.path=$JNETPCAP_HOME - You can change working directory into the root of jnetpcap's installation directory. * For further trouble shooting information, please see the following link: (http://jnetpcap.wiki.sourceforge.net/Troubleshooting+native+library)