tags:

views:

40

answers:

1

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
Bundle-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.

A: 

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.

Holger Hoffstätte