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

2023-12-01

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

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

我正在运行下面的 example.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<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)

请就问题所在提出建议。


我这样解决了同样的问题:

  1. 使用Ubuntu 16.04

  2. 手动安装jre-1.8.0_181:

    • 下载特定的java版本(https://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html) jre-8u181-linux-x64.tar.gz
    • 创建java目录:mkdir /opt/jre
    • 提取java:tar -zxf jre-8u181-linux-x64.tar.gz
    • 更新使用的java版本:更新替代方案 --install /usr/bin/java java /opt/jre/jre1.8.0_181/bin/java 100
  3. 下载、解压 jnetpcap 文件并将其复制到 lib 目录

    • wget -O jnetpcap-1.4.r1425 https://downloads.sourceforge.net/project/jnetpcap/jnetpcap/Latest/jnetpcap-1.4.r1425-1.linux64.x86_64.tgz
    • tar -xvf jnetpcap-1.4.r1425
    • cp jnetpcap-1.4.r1425/libjnetpcap.so /lib/
  4. 运行你的程序

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

jnetpcap - java.lang.UnsatisfiedLinkError: com.slytechs.library.NativeLibrary.dlopen(Ljava/lang/String;)J 的相关文章

随机推荐