2

我已经成功地从代码中启动了 Apache Felix 并注册了一个自己的 Bundle。

需要以下 OSGI 项目之间的关系:

[OsgiInterface]-- 提供接口。

[OsgiModuleA]-- (bundle) 提供这些接口的实现。
知道[OsgiInterface]

[OsgiUsage]-- 使用一个或多个捆绑包。
知道[OsgiInterface]并且[OsgiModuleA]

现在我在注册实现接口的服务时遇到问题。我猜我在manifest.mf文件中的条目是错误的。

附加信息

如果有人可以查看我上一个问题中的代码,那就太好了

让我参考一下这个问题:

我试图创建第三个项目OsgiInterfacesSomeInterface ,它在包中提供了一个接口interfacesOsgiModuleAOsgiUsage都知道这个项目。

OsgiModuleA: manifest.mf现在interfaces为 entry增加了一个值Import-Package:。此外,还有一个SomeInterface提供给激活器的实例。

当捆绑包启动时,NoClassDefFoundError会发生:接口SomeInterface未知。

编辑:

现在,错误已修复,我可以说,最重要的部分是:

map.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
    "my.interfaces; version=1.0.0");

没有这个,我得到了ClassCastException.

4

4 回答 4

5

在最基本的形式中,服务是在 Java 代码中注册的,而不是使用清单或任何其他文件。这通常发生在您的 BundleActivator 中。

Long      i     = new Long(20);    // the service implementation
Hashtable props = new Hashtable();
props.put("description", "This an long value");
bundleContext.registerService(Long.class.getName(), i, props);

我建议您阅读教程,例如Knopflerfish上的教程

另一种方法是使用声明式服务或新的蓝图工具。使用这些(或其他非标准化系统)中的任何一个,您将在(通常是 XML)文件中声明您的服务,而不是编写代码来与服务注册表交互。

但是您可能应该首先手动弄清楚基本原理。

[OsgiUsage] -- 使用一个或多个捆绑包。知道 [OsgiInterface] 和 [OsgiModuleA]

使用服务的捆绑软件不必知道提供它的捆绑软件。他们都只需要知道服务接口。事实上,bundle 根本不需要知道其他的 bundle。他们只需要导入包,消费或提供服务。

于 2009-12-14T07:11:08.723 回答
2

I understand that you have SomeInterface in another bundle, right? Then you must also export that package in that bundle's manifest, eg.

Export-Bundle: interfaces

But you really should have a look at the bnd tool mentioned in another answer. This generates standard OSGi manifests.

于 2009-12-13T01:50:18.003 回答
1

我建议你看看 iPOJO 项目。这使得使用 Felix 变得更加容易。
https://felix.apache.org/documentation/subprojects/apache-felix-ipojo.html

于 2009-12-13T15:19:26.003 回答
0

我会说直接使用bndmaven-bundle-plugin来创建启用 OSGI 的 jar。

这比自己编写 OSGI 清单更容易(错别字、错误、缺少导入/导出)

尝试用 bnd 包装罐子作为开始。

于 2009-12-12T15:41:34.280 回答