2016-08-19 698 views
3

我正在使用IntelliJ运行示例java-jnetpcap应用程序。我在类路径中的64位JDK,包括如下依赖jnetpcap - java.lang.UnsatisfiedLinkError:com.slytechs.library.NativeLibrary.dlopen(Ljava/lang/String;)J

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

我正在下面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<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) 

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

+0

Websearches为'com.slytechs.library.NativeLibrary.dlopen'带来了一定的成效。他们中的大多数人建议你必须手动将'.so'文件复制到某个目录(本地库通常不通过maven处理 - 这很不幸: - /)。你已经尝试了一些这些方法,并将本地库复制到可以找到它的目录? – Marco13

+0

你能粘贴一个这样的网址,清楚地解释它吗?我已经尝试了一些方法,但没有复制.so文件。 – thevillageguy

+0

IntelliJ的过程应该类似于http://jnetpcap.com/?q=eclipse(或NetBeans)上的过程。我不熟悉IntelliJ,但是...你可以尝试复制本地库(Linux上的'.so'文件,Windows上的'.dll'文件,Mac上的'.dylib'文件)到主目录你的项目。你试过什么了? – Marco13

回答

0

我也遇到了这个异常,并发现我忘记了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)