简体   繁体   中英

OSGI JNA native library pcap not found

I'm using pcap4j in my OSGI project. The devices the application is running on is running openembedded. When I'm running my code in a standalone application (non OSGI) on a device, it works without problem. When running inside an OSGI it doesn't. I embedded the pcap4j dependencies as they are not bundles. The manifest contains the import of com.sun.jna and the bundle jna 4.2.0 is available (and used by another bundle). I also tried by calling System.load and System.loadLibrary...

I've got the same problem too and I made an osgi bundle for pcap4j and its dependents. Here's the jar files in the bundle:

jna-4.2.1.jar, 
pcap4j-core-1.7.3.jar, 
pcap4j-packetfactory-static-1.7.3.jar,
slf4j-api-1.7.12.jar, 
slf4j-nop-1.6.2.jar

The entire MANIFEST.MF file:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Pcap4j
Bundle-SymbolicName: pcap4j
Bundle-Version: 1.0.0
Bundle-ClassPath: jna-4.2.1.jar, pcap4j-core-1.7.3.jar, pcap4j-packetfactory-static-1.7.3.jar, slf4j-api-1.7.12.jar, slf4j-nop-1.6.2.jar
Export-Package: com.sun.jna,com.sun.jna.ptr,com.sun.jna.win32,org.pcap4j,org.pcap4j.core,org.pcap4j.packet,org.pcap4j.packet.constant,org.pcap4j.packet.factory,org.pcap4j.packet.namednumber,org.pcap4j.util,org.slf4j,org.slf4j.helpers,org.slf4j.impl,org.slf4j.spi
Bundle-RequiredExecutionEnvironment: JavaSE-1.8

After that you can simply use these packages using Import-Package.

Import-Package: org.osgi.framework;version="1.3.0", org.pcap4j.core, org.pcap4j.packet, org.pcap4j.packet.namednumber

Also look at this issue on pcap4j repository to more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM