开发者

Question about loading DLL (using JNA) inside an OSGi bundle

开发者 https://www.devze.com 2023-01-11 22:01 出处:网络
Currently I have the DLL files (rfid.dll;cpl.dll;rfidtx.dll;) at the root of my bundle. I make a Utility Bundle to hold the jna.jar, and export com.sun.jna, com.sun.jna.ptr as services.

Currently I have the DLL files (rfid.dll;cpl.dll;rfidtx.dll;) at the root of my bundle. I make a Utility Bundle to hold the jna.jar, and export com.sun.jna, com.sun.jna.ptr as services.

The Manifest for the bundle in question looks something like this:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ServiceImpl
Bundl开发者_高级运维e-SymbolicName: osgi.mti.serviceImpl
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: ZTESOFT
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: osgi.mti.service,
 org.osgi.service.component;version="1.1.0",
 com.sun.jna,
 com.sun.jna.ptr
Service-Component: OSGI-INF/component.xml
Bundle-NativeCode: rfid.dll;cpl.dll;rfidtx.dll;
 osname=WindowsXP;
 processor=x86

In my code, the JNA interface is declared as:

   public interface CLibrary extends Library {

    CLibrary INSTANCE = (CLibrary) Native.loadLibrary("rfid",
            CLibrary.class);
   ............

}

When I running there are some exception messages displayed. The root exception is:

    java.lang.UnsatisfiedLinkError: Unable to load library 'rfid'

So, how can I solve this problem? I hope someone can help me.


See this existing question for an in-depth explanation. JNA is not OSGi-aware and itself uses native code to load libraries. Apparently you can preload the native library (letting OSGi do the work, as it should), which will then satisfy JNA's native hook. You should then be able to use the JNA-exposed APIs through your service. Please report back if this works - I have very successfully used "regular" JNI with OSGi and also briefly tried to use JNA, but got nowhere because of its own loader hook.

0

精彩评论

暂无评论...
验证码 换一张
取 消