包含OSGi捆绑包的其他资源 [英] Including additional resources with OSGi bundles

查看:117
本文介绍了包含OSGi捆绑包的其他资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个OSGi包,它实现了一个服务作为本机可执行文件的包装器。也就是说,该服务使用 ProcessBuilder 运行可执行文件,为其提供一些数据,并检索结果。我的问题是打包这个包的最佳方法。本机可执行文件包括许多依赖数据文件,这些文件必须全部存在于磁盘上才能运行该工具。我已经找到了很多关于在OSGi中处理本机DLL的参考资料,但没有找到与磁盘相关联的文件,这些磁盘必须存在于磁盘上而不是只能通过类路径检索。

I'm working on an OSGi bundle which implements a service as a wrapper around a native executable. That is, the service runs the executable with ProcessBuilder, feeds it some data, and retrieves the result. My question is about the best way to package this bundle. The native executable includes a number of dependent data files which all must be present on disk for the tool to run. I've found plenty of references on dealing with native DLLs in OSGi, but none that address files associated with a bundle that must be present on disk rather than just retrievable through the classpath.

我原以为我可以直接在bundle archive中包含exectuable和dependent文件,然后在bundle启动时以编程方式提取到某个目录。我能想到的另一个选择是将可执行文件放在某处并设置指向它的系统属性,但我希望将配置保持在最低限度。

I was thinking that I could include the exectuable and dependent files directly in the bundle archive and then programmatically extract to some directory when the bundle is started. The other option I can think of is to put the executable somewhere and set a system property that points to it or something, but I want to keep configuration to a minimum.

一个不特定于特定OSGi实现的解决方案会很好,但如果没有,我会使用Equinox。

A solution that isn't specific to a particular OSGi implementation would be nice, but if not, I'm using Equinox.

谢谢!

推荐答案

这些附加文件是否需要由本机代码写入?如果没有,没有什么可以阻止你把你喜欢的任何文件放在一个包中。

Do these additional files need to be writeable by the native code? If not, there's nothing stopping you putting any files you like inside a bundle.

你在OSGi中遇到的常见问题是找出文件的路径,因为OSGi没有假设文件系统可用(它并不像OSGi在嵌入式设备中启动时那么奇怪)。

The usual problem you have in OSGi is working out the path to the file as OSGi does not assume a file system is available (it's not as strange as it sounds as OSGi started out in embedded devices).

如何控制本机代码查找其相关内容的位置文件?你需要传递一个路径吗?

How do you control where the native code looks for its related files? Do you need to pass it a path?

如果你想要一个目录来复制或解包东西,那么使用:

If you want a directory to copy or unpack stuff, then use:

org.eclipse.core.runtime.Platform.getStateLocation()

它为您提供了捆绑包的工作目录。

Which gives you the working directory for the bundle.

如果要查找捆绑包中特定文件的路径,可以执行以下操作: p>

If you want to find the path for a particular file in your bundle, you can do:

org.eclipse.core.runtime.FileLocator.toFileURL((context.getBundle().getEntry("/etc/readme.txt")))

在这种情况下,将返回<$ c $的文件URL当前包中的c> /etc/readme.txt 。

Which, in this case, will return an file URL to the /etc/readme.txt in the current bundle.

这两段代码都假设它们位于激活器的 start()方法。

Both pieces of code assume they are inside the activator's start() method.

这篇关于包含OSGi捆绑包的其他资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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