2016-08-19 6 views
3

샘플 java-jnetpcap 응용 프로그램을 실행하려면 IntelliJ를 사용하고 있습니다. 나는 클래스 경로에 64 비트 JDK가 나는 아래 sample.java 클래스jnetpcap - java.lang.UnsatisfiedLinkError : com.slytechs.library.NativeLibrary.dlopen (Ljava/lang/String;) J

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"); 
} 
} 

그것은 아래 예외를 던지고 실행하고

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

다음과 같은 의존성 포함 :

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

명확하게 설명하는 URL을 붙여 줄 수 있습니까? 나는 이미 몇 가지 접근법을 시도했으나 .so 파일은 복사하지 않았다. – thevillageguy

+0

IntelliJ의 프로세스는 http://jnetpcap.com/?q=eclipse (또는 NetBeans의 경우)와 유사해야합니다. 나는 IntelliJ에 익숙하지 않다. 그러나 ... 네이티브 라이브러리 (리눅스의'.so' 파일, 윈도우의'.dll' 파일, Mac의 .dylib' 파일)를 메인 디렉토리에 복사 해 볼 수있다. 귀하의 프로젝트. 지금까지 뭐 해봤 어? – Marco13

답변

0

이 예외도 발생하여 RELEASE_NOTES.txt에서 설치 단계를 잊어 버린 것을 발견했습니다.

라이브러리는 OS 기본 위치에 있지 않거나 자바를 찾을 수없는 경우 바이너리를 찾지 못합니다. 나를 위해, 지시에 따라이 오류가 사라졌습니다.

이 소스 재료보다 더 나은 요약하기 어렵다, 그래서 나는 바로 여기에 붙여 넣을 수 있습니다 :

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) 
관련 문제