依赖 – Osgi将不匹配bundle内的本机代码

我正在尝试使用具有本机代码依赖性的某个 Eclipse插件.这些依赖项总是无法解决,所以这个插件永远不会被OSGI加载.

MANIFEST.MF

Manifest-Version: 1.0
    Bundle-ManifestVersion: 2
    Bundle-Name: PROS Cortex Flash Utility
    Bundle-SymbolicName: com.purduesigbots.vexflash; singleton:=true
    Bundle-Version: 1.0.0.6
    Bundle-Activator: com.purduesigbots.vexflash.Activator
    Bundle-Vendor: Purdue ACM SIG BOTS
    Require-Bundle: org.eclipse.ui,org.eclipse.core.runtime,org.eclipse.co
     re.resources,org.eclipse.ui.ide;bundle-version="3.7.0",org.eclipse.de
     bug.ui;bundle-version="3.7.0"
    Bundle-RequiredExecutionEnvironment: JavaSE-1.6
    Bundle-ActivationPolicy: lazy
    Bundle-NativeCode:
      /libs/windows/jSSC-2.6_x86_64.dll;
      osname=win32; processor=x86_64,*
    Bundle-ClassPath: .,jna.jar,platform.jar

dll的路径是包jar内的/libs/windows/jSSC-2.6_x86_64.dll.我尝试了许多不同的东西来尝试让本机加载,但没有成功.

如何让OSGI加载本机库?我在Windows 10上运行JRE 8 64位.

编辑:

我这样修改了MANIFEST.MF以使其工作

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: PROS Cortex Flash Utility
Bundle-SymbolicName: com.purduesigbots.vexflash; singleton:=true
Bundle-Version: 1.0.0.6
Bundle-Activator: com.purduesigbots.vexflash.Activator
Bundle-Vendor: Purdue ACM SIG BOTS
Require-Bundle: org.eclipse.ui,org.eclipse.co
 re.resources,org.eclipse.de
 bug.ui;bundle-version="3.7.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-NativeCode:
#The OS name is not in OS aliases for OSGI,so the full name must be used
  /libs/windows/jSSC-2.6_x86_64.dll;
  osname=win32; osname="Windows 10"; processor=x86_64
Bundle-ClassPath: .,platform.jar

解决方法

在我的例子中,在将JRE从1.8.0.5更新到1.8.0.162之后,有一个RCP应用程序在DLL上停止了UnsatisfiedLinkError.经过一些搜索,我发现有两个错误,one in Javaone in OSGi,在Windows 10下的Bundle-NativeCode指令中使用win32别名时相互取消.在更新之前它的工作原因是,Java会掉线如果它不知道Windows返回的版本,则返回默认值. OSGi和 matched with the win32 alias都知道这种后退.
现在更新Java意味着不再使用默认值,而是使用“Windows 10”.但是,前Luna版本的OSGi不知道Windows 10,因此与win32别名不匹配.

我使用的解决方法是相应地覆盖org.osgi.framework.os.name属性,这是可行的,因为该应用程序没有其他目标:

-Dorg.osgi.framework.os.name=win32

在大多数情况下,更好的解决方案是将OSGi更新到至少3.10.0.

当然,像作者那样将“Windows 10”作为附加的os.name添加到Manifest中也可以.我决定反对这一点,因为我在依赖项中有几个这样的原生二进制文件,这些文件不在我的控制之下.

相关文章

什么是设计模式一套被反复使用、多数人知晓的、经过分类编目...
单一职责原则定义(Single Responsibility Principle,SRP)...
动态代理和CGLib代理分不清吗,看看这篇文章,写的非常好,强...
适配器模式将一个类的接口转换成客户期望的另一个接口,使得...
策略模式定义了一系列算法族,并封装在类中,它们之间可以互...
设计模式讲的是如何编写可扩展、可维护、可读的高质量代码,...