无法使用 bndtools 启动声明式服务 (DS) 组件

cannot startup a Declarative Services (DS) component using bndtools

我已经安装了用于 eclipse 的标准 bndtools 插件以及 运行 apache felix osgi 运行时。我正在尝试了解声明式服务 (DS) 组件。显然,在有注释之前(在 bndtools 教程中给出了一个例子),组件是使用 xml 数据编写的。这就是我想要做的。

这是简单的 class(将作为 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)
    5|Active     |    1|BookReaderOSGiInPractice.minimal_ds (0.0.0.201509091856)
   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)

尽管一切都在活跃 运行,但我无法弄清楚为什么 DS 组件没有被初始化(我应该看到控制台输出:"HelloComponent created.")。感谢任何帮助。

最后,这是项目目录结构:

BookReaderInPractice
|
|- src
|   |- org.osgi.book.ds.minimal
|           |_ HelloComponent.java
|
|- minimal_ds.bnd
|
|- minimal.xml

更新(已编辑)

根据 Neil Bartlett 的建议更新:原来答案更简单:正如我在评论中所写,DS xml 文件的 xml 命名空间中有一个拼写错误:"xlm" 而不是 "xml".

原回答:

我想这里有两件事出了问题:

  1. 文件minimal.xml没有被复制到生成的bundle jar中 (位于 "generated" 文件夹中)
  2. 框架不知道minimal.xml

要解决此问题,请将以下行放入 minimal_ds.bnd:

Include-Resource: minimal.xml
Service-Component: minimal.xml

此外,不要使用 HelloComponent 的构造函数,而是创建一个在激活组件时调用的方法:

public void activate() {...}