osgi应用程序中的非osgi库使用 [英] Non-osgi library usage in an osgi application

查看:196
本文介绍了osgi应用程序中的非osgi库使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在OSGi应用程序中使用非osgi库?

Is it possible to use a non-osgi library with an OSGi application?

举个例子,我正在开发一个基于语义的搜索引擎,我就是使用第三方自然语言处理库( http://wiki.opencog.org/w/RelEx_Dependency_Relationship_Extractor )。

For an example, I'm developing a semantic based search engine, and I am using a third party Natural Language Processing library for it (http://wiki.opencog.org/w/RelEx_Dependency_Relationship_Extractor).

是否有可能将这样一个不支持OSGi的库作为几个jar文件与我的OSGi应用程序接口?

Is it possible to interface such a library which doesn't suport OSGi, as a couple of jar files, with my OSGi application?

推荐答案

如前所述,如果您想在捆绑包中使用其他库,则有两个选项:

As it was written in previous answers you have two options if you want to use additional libraries in your bundles:


  1. 将库jar嵌入到将要使用的包中,

  2. 从库中创建有效的OSGi包。

第一种方法更简单,因为您只需要将库jar(及其所有依赖项)复制到一个包(例如,一个根目录)然后将它们添加到 MANIFEST.MF 中的 Bundle-Classpath 元素(参见这里)。但是,在执行此操作时,您必须记住,此添加的库仅在嵌入它的包中可见(因此库重用受限)。您始终可以将此库中的包添加到 MANIFEST.MF 中的 Export-package 元素,以使其对其他包可见但这远不是优雅的解决方案(但它会起作用)。

The first approach is simpler because you only need to copy library jars (and all its dependencies) to a bundle (e.g. to a root directory) and then add them to Bundle-Classpath element in MANIFEST.MF (see here). However, while doing this you must remember that this added library will be visible only in a bundle in which it is embedded (so library reuse is limited). You could always add packages from this library to Export-package element in MANIFEST.MF to make it visible for other bundles but this is far from elegant solution (however it will work).

为了让其他捆绑包可见,你应该使用第二种方法,即从库中创建一个OSGi包(有一些工具可以帮助你这样做,也在Eclipse中)。但是,对于更复杂的库,这种方法可能更难(因为OSGi中的依赖关系和特定的类加载方法)。

In order to make it visible to other bundles you should use the second approach, i.e. create an OSGi bundle from the library (there are tools which can help you in doing that, also in Eclipse). However, for more complicated libraries this approach may be harder (because of dependencies and specific class loading approach in OSGi).

因此,如果您只想在一个库中使用该库我建议使用第一种方法(它更容易实现)。如果您想在应用程序的许多软件包中使用此库,您应该考虑第二种方法。

So if you want to use the library only in one bundle I suggest using the first approach (it is easier to implement). If you want to use this library in many bundles in your application you should consider the second approach.

这篇关于osgi应用程序中的非osgi库使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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