I have got the standard bndtools plugin for eclipse installed, up and also running the apache felix osgi runtime. I am trying to learn about declarative services (DS) components. Apparently, before there were annotations (for which an example is given in the tutorial for bndtools), components were written using xml data. That is what I am trying to do.
Here is the simple class (which will be published as a DS component): "HelloComponent.java"
package org.osgi.book.ds.minimal;
public class HelloComponent {
public HelloComponent(){
System.out.println("HelloComponent created.");
}
}
Here is the xml file that makes a component declaration: "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>
And here is the .bnd file that's supposed to be used by the bndtools to generate the jar files which will eventually be published to the OSGi runtime: "minimal_ds.bnd"
Private-Package: org.osgi.book.ds.minimal
Include-Resource: minimal.xml
Service-Component: minimal.xml
Note that I have the following bundles up and running in the host runtime OSGi container:
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)
Despite everything being actively running, I can't figure out why the DS component is not being initialized (to which I should see the console output: "HelloComponent created."). Any help is appreciated.
Finally, here is the project directory structure:
BookReaderInPractice
|
|- src
| |- org.osgi.book.ds.minimal
| |_ HelloComponent.java
|
|- minimal_ds.bnd
|
|- minimal.xml
Update (Edited):
updated as suggested by Neil Bartlett: Turns out the answer was even simpler: as written in my comment, there was a typo in the xml namespace of the DS xml file: "xlm" instead of "xml".
Original answer:
I guess there are two things going wrong here:
To fix this, put the following lines into minimal_ds.bnd:
Include-Resource: minimal.xml
Service-Component: minimal.xml
Furthermore, instead of using the constructor of HelloComponent, create a method like this which will be called when activating the component:
public void activate() {...}