关于在 OSGi 包中加载 DLL(使用 JNA)的问题

发布于 2024-09-14 00:28:24 字数 991 浏览 12 评论 0原文

目前,我的捆绑包根目录下有 DLL 文件(rfid.dll;cpl.dll;rfidtx.dll;)。 我制作了一个实用程序包来保存 jna.jar,并将 com.sun.jna、com.sun.jna.ptr 作为服务导出。

有问题的包的清单看起来像这样:

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

在我的代码中,JNA 接口声明为:

   public interface CLibrary extends Library {

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

}

当我运行时,会显示一些异常消息。根本的例外是:

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

那么,我该如何解决这个问题呢?我希望有人能帮助我。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴情换悲伤 2024-09-21 00:28:24

请参阅现有问题以获取深入说明。 JNA 不支持 OSGi,它本身使用本机代码来加载库。显然,您可以预加载本机库(让 OSGi 完成工作,因为它应该这样做),这将满足 JNA 的本机挂钩。然后,您应该能够通过您的服务使用 JNA 公开的 API。如果这有效,请报告 - 我已经非常成功地将“常规”JNI 与 OSGi 一起使用,并且还短暂尝试使用 JNA,但由于其自己的加载器挂钩而无处可去。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文