我已經獲得了安裝eclipse的標準bndtools插件,並且還運行了Apache felix osgi運行時。我正在嘗試瞭解聲明式服務(DS)組件。顯然,在註釋之前(在bndtools教程中給出了一個示例),組件是使用xml數據編寫的。這正是我想要做的。無法使用bndtools啓動聲明性服務(DS)組件
這裏是簡單的類(其將被髮布爲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
的線你建議已經包含在minimal_ds.bnd中。此外,當我查看生成的jar時,還包含了minimal.xml以及java src包。使用activate方法也不會輸出任何控制檯消息。謝謝你嘗試,雖然... –
糟糕...完全錯過了,對不起。但是我現在在minimal.xml的xml命名空間中發現了一個錯字:嘗試「http://www.osgi.org/xmlns/scr/v1.1。0「,它會工作;) – evandor
作品像魔術.. :)謝謝你evandor。 –