jnetpcap - java.lang.UnsatisfiedLinkError:com.slytechs.library.NativeLibrary.dlopen(Ljava / lang / String;)J [英] jnetpcap - java.lang.UnsatisfiedLinkError: com.slytechs.library.NativeLibrary.dlopen(Ljava/lang/String;)J

查看:774
本文介绍了jnetpcap - java.lang.UnsatisfiedLinkError:com.slytechs.library.NativeLibrary.dlopen(Ljava / lang / String;)J的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using IntelliJ to run a sample java-jnetpcap application. I have 64 bit JDK in the class path and included the following dependency

<dependency>
  <groupId>jnetpcap</groupId>
  <artifactId>jnetpcap</artifactId>
  <version>1.4.r1425-1f</version>
</dependency>

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

I am running the below sample.java class

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<String> jpacketHandler = new PcapPacketHandler<String>() {
  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");
}
}

抛出以下异常:

 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.<init>(Unknown Source)
at com.slytechs.library.JNILibrary.<init>(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.<clinit>(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)

建议你输入错误的地方。

Please suggest your inputs on where it is going wrong.

推荐答案

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

I ran into this exception as well, and discovered that I had forgotten an installation step from RELEASE_NOTES.txt.

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

The library will fail to find the binaries unless they're placed in an OS default location, or Java is given some way to find them. For me, following the directions made this error go away.

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

It's hard to summarize it better than the source material, so I'll paste it here directly:

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)

这篇关于jnetpcap - java.lang.UnsatisfiedLinkError:com.slytechs.library.NativeLibrary.dlopen(Ljava / lang / String;)J的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆