如何使用OSGi片段来提供具有相同文件名的依赖于平台的本机代码? [英] How to use OSGi fragments to contribute platform-dependent native code with the same filename?

查看:192
本文介绍了如何使用OSGi片段来提供具有相同文件名的依赖于平台的本机代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JNotify 项目来监听文件系统事件。这取决于每个操作系统的一个本机库:处理器架构。例如,有一个用于Windows x86的库,一个用于x86-64的库等。

I am using the JNotify project to listen to file system events. This depends on one native library per OS:processor architecture. For example, there's one library for Windows x86, one library for x86-64 etc.

最初,我有一个包含JNotify Java类和本机代码的包。本机代码在Bundle-NativeCode中声明如下:

Originally, I had one bundle that contained both the JNotify Java classes and the native code. The native code were declared in Bundle-NativeCode as follows:

(为了更好的可读性,我将这些格式化为bnd样式...显然是实际的MANIFEST.MF文件正确形成)。

(I've formatted these in the bnd style for better readibility... obviously the actual MANIFEST.MF files are properly formed).

Bundle-NativeCode: jnotify_64bit.dll;osname=Win32;osname="Windows NT (unknown)";osname = WindowsXP;osname = Windows2000;osname = Windows2003;osname = WindowsVista;osname = Windows7;osname = WindowsServer2008;osname= Windows8;osname = WindowsServer2012;processor = x86-64,\
 jnotify.dll;osname=Win32;osname="Windows NT (unknown)";osname = WindowsXP;osname = Windows2000;osname = Windows2003;osname = WindowsVista;osname = Windows7;osname = WindowsServer2008;osname = Windows8;osname = WindowsServer2012;processor = x86,\
 libjnotify.so;osname = Linux;processor = x86,\
 libjnotify64.so;osname = Linux;processor = x86-64,\
 libjnotify.dylib;osname = Mac OSX;processor = x86;processor = x86-64,\
 *

这很好用。

I如果我将库移动到单独的片段包中,那将是不错的,这样我就可以为我感兴趣的架构贡献片段。以Linux为例,我将它们分成两个包:

I figured it would be 'nice' if I moved the libraries into separate fragment bundles so that I could just contribute the fragments for the architecture I am interested in. Taking the example of Linux, I split them into two bundles:

Linux 32位

Include-Resource: lib/libjnotify.so
Bundle-NativeCode: libjnotify.so;osname = Linux;processor = x86,\
    *
Fragment-Host: net.contentobjects.jnotify
Bundle-Version: 0.94.0

Linux 64位

Include-Resource: lib/libjnotify.so
Bundle-NativeCode: libjnotify.so;osname = Linux;processor = x86-64,\
    *
Fragment-Host: net.contentobjects.jnotify
Bundle-Version: 0.94.0

请注意,这些捆绑包是根据不同的来源构建的。虽然libjnotify.so文件名是相同的,但它们是不同Eclipse项目中的不同文件。它们必须与JNotify一样。

Note that these bundles are built from different source. Although the libjnotify.so filename is the same they are different files in different Eclipse projects. They have to be the same to work with JNotify.

请注意,相同的文件名将提供给主机包。在这种情况下,文件名是libjnotify.so。

Note that the same filename is contributed to the host bundle. In this case the filename is libjnotify.so.

如果我在我的64位机器上运行这些,并且在 32位之前加载了64位软件包工作。

If I run these on my 64 bit machine with the 64 bit bundle being loaded before the 32 bit one, it works.

但是,如果首先加载32位捆绑包,我会得到:

However, if the 32 bit bundle gets loaded first, I get:

Couldn't initialise JNotify: java.lang.UnsatisfiedLinkError: /blah/generated/fw/bundle46/version0.0/net.contentobjects.jnotify.linux.x86-0.94.0.jar-lib/0/libjnotify.so: /blah/generated/fw/bundle46/version0.0/net.contentobjects.jnotify.linux.x86-0.94.0.jar-lib/0/libjnotify.so: wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch) (JnotifyFileSystemObserver.java:53, thread platformExecutor)

显然32位库是被装载。 但为什么? My Bundle-NativeCode定义主机必须是32位Linux机器才能使用32位软件包的版本。我认为如果该子句不匹配,库将被忽略?

Clearly the 32 bit library is being loaded. But why? My Bundle-NativeCode defines the host must be a 32 bit Linux machine to use the 32 bit bundle's version. I thought if that clause doesn't match, the library is ignored?


  • 删除可选的通配符...这只是意味着捆绑包无法解析

推荐答案

由于您的片段占用相同的资源名称空间,因此只能访问一个.so文件。您只能部署一个片段,或者您可以尝试将它们放在不同的目录中:

Since your fragment occupy the same resource namespace only one .so file can be accessed. You can deploy only one fragment, or you could try putting them in different directories:

 Fragment 32-bit:
 Include-Resource: x32/libjnotify.so=lib/libjnotify.so

 Fragment 64-bit:
 Include-Resource: x64/libjnotify.so=lib/libjnotify.so

我还认为你需要将Bundle-NativeCode标头放在主机包中并引用正确的目录,因为我我认为此标头未在主机中合并。

I also think you need to put the Bundle-NativeCode header in the host bundle and refer to the proper directories since I am I think this header is not merged in the host.

这篇关于如何使用OSGi片段来提供具有相同文件名的依赖于平台的本机代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆