我已经为 Eclipse 安装了标准bndtools插件,启动并运行了 apache felix osgi 运行时。我正在尝试了解声明式服务 (DS) 组件。显然,在没有注释之前(bndtools 教程中给出了一个示例),组件是使用 xml 数据编写的。这就是我想要做的。
这是一个简单的类(将作为 DS 组件发布):“HelloComponent.java”
package org.osgi.book.ds.minimal;
public class HelloComponent {
public HelloComponent(){
System.out.println("HelloComponent created.");
}
}
这是进行组件声明的 xml 文件:“minimal.xml”
<?xml version="1.0" encoding="UTF-8"?>
<!-- minimal.xml -->
<scr:component xmlns:scr="http://www.osgi.org/xlmns/scr/v1.1.0" immediate="true">
<implementation class="org.osgi.book.ds.minimal.HelloComponent"/>
</scr:component>
这是应该由 bndtools 用来生成最终将发布到 OSGi 运行时的 jar 文件的 .bnd 文件:“minimal_ds.bnd”
Private-Package: org.osgi.book.ds.minimal
Include-Resource: minimal.xml
Service-Component: minimal.xml
请注意,我在主机运行时 OSGi 容器中启动并运行了以下捆绑包:
ID|State |Level|Name
0|Active | 0|System Bundle (4.4.1)
2|Active | 1|Apache Felix Gogo Command (0.14.0)
3|Active | 1|Apache Felix Gogo Runtime (0.12.1)
4|Active | 1|Apache Felix Gogo Shell (0.10.0)
15|Active | 1|Apache Felix Configuration Admin Service (1.8.0)
16|Active | 1|Apache Felix Declarative Services (1.8.2)
17|Active | 1|osgi.enterprise (4.2.0.201003190513)
18|Active | 1|osgi.residential (4.3.0.201111022239)
最后,这里是项目目录结构:
BookReaderInPractice
|
|- src
| |- org.osgi.book.ds.minimal
| |_ HelloComponent.java
|
|- minimal_ds.bnd
|
|- minimal.xml
问题是,当我尝试为“最小”安装捆绑包时,出现缺少要求的错误。我得到的确切错误是:
missing requirement Require[osgi.extender]{}{filter=(&(osgi.extender=osgi.ds)(version>=1.1.0)(!(version>=2.0.0))), effective=active}]
网络上的一些资源说这是早期版本的 bndtools 的错误。当然,我仍然能够编译和运行这个包几天,没有任何问题。然后,在某个时候,它就停在了那里!“重新构建”、“重新生成” jar 文件以及将项目完全复制到新的 Eclipse 工作区中似乎没有任何效果。
这是我正在使用的:
OS-X 10.9 Maverics, Eclipse Luna Service Release 1 (4.4.1) BndTools: 2.4.1 (最新)
有人似乎有线索吗?