I think you need a bundle providing the SCR runtime:

http://felix.apache.org/documentation/subprojects/apache-felix-service-component-runtime.html

Without a DS implementation it simple won't do anything.

regards, Frank

On Mon, Aug 1, 2016 at 5:29 PM, <[email protected]> wrote:

> Hello.
>
> I'm learning to use OSGi and am using Felix as the container. I have a
> trivial Maven project that implements a simple service. There are two
> implementations: One using the old style BundleActivator interface and
> the other using modern declarative service annotations.
>
> API module:
>
>
> https://github.com/io7m/osgitest-20160801/blob/master/service0-api/src/main/java/com/io7m/service0/api/SpeakerType.java
>
> https://github.com/io7m/osgitest-20160801/blob/master/service0-api/pom.xml
>
> Old-style BundleActivator-based service:
>
>
> https://github.com/io7m/osgitest-20160801/blob/master/service0-provider-imperative/src/main/java/com/io7m/service0/provider_imperative/Speaker.java
>
> https://github.com/io7m/osgitest-20160801/blob/master/service0-provider-imperative/pom.xml
>
> New declarative style service:
>
>
> https://github.com/io7m/osgitest-20160801/blob/master/service0-provider-declarative/src/main/java/com/io7m/service0/provider_declarative/Speaker.java
>
> https://github.com/io7m/osgitest-20160801/blob/master/service0-provider-declarative/pom.xml
>
> The manifest created by compiling the "imperative" module looks correct
> (the text wrapping is actually present in the manifest):
>
> --8<--
> Manifest-Version: 1.0
> Bnd-LastModified: 1470064469312
> Build-Jdk: 1.8.0_92
> Built-By: someone
> Bundle-Activator: com.io7m.service0.provider_imperative.Speaker
> Bundle-License: http://io7m.com/license/isc.txt
> Bundle-ManifestVersion: 2
> Bundle-Name: service0-provider-imperative
> Bundle-SymbolicName: com.io7m.experimental.service0-provider-imperative
> Bundle-Version: 0.1.0
> Created-By: Apache Maven Bundle Plugin
> Export-Package: com.io7m.service0.provider_imperative;uses:="com.io7m.se
>  rvice0.api,org.osgi.framework";version="0.1.0",com.io7m.service0.api;ve
>  rsion="0.1.0"
> Import-Package: com.io7m.service0.api;version="[0.1,0.2)",org.osgi.frame
>  work;version="[1.8,2)"
> Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
> Tool: Bnd-3.2.0.201605172007
> -->8--
>
> When the bundle is installed and started in Felix, I get the expected
> messages on stdout:
>
> g! install
> service0-provider-imperative/target/service0-provider-imperative-0.1.0.jar
> Bundle ID: 5
> g! start 5
> DEBUG: WIRE: [com.io7m.experimental.service0-provider-imperative
> [5](R5.0)]
> osgi.wiring.package;(&(osgi.wiring.package=org.osgi.framework)(version>=1.8.0)(!(version>=2.0.0)))
> -> [org.apache.felix.framework [0](R 0)]
> DEBUG: WIRE: [com.io7m.experimental.service0-provider-imperative [5](R
> 5.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.8)) ->
> [org.apache.felix.framework [0](R 0)] Speaker: constructor
> Speaker: start org.apache.felix.framework.BundleContextImpl@3870e6b0
>
> The manifest created by compiling the "declarative" module looks correct:
>
> --8<--
> Manifest-Version: 1.0
> Bnd-LastModified: 1470064469068
> Build-Jdk: 1.8.0_92
> Built-By: someone
> Bundle-License: http://io7m.com/license/isc.txt
> Bundle-ManifestVersion: 2
> Bundle-Name: service0-provider-declarative
> Bundle-SymbolicName: com.io7m.experimental.service0-provider-declarative
> Bundle-Version: 0.1.0
> Created-By: Apache Maven Bundle Plugin
> Export-Package: com.io7m.service0.provider_declarative;uses:="com.io7m.s
>  ervice0.api";version="0.1.0",com.io7m.service0.api;version="0.1.0"
> Import-Package: com.io7m.service0.api;version="[0.1,0.2)"
> Provide-Capability: osgi.service;objectClass:List<String>="com.io7m.serv
>  ice0.api.SpeakerType"
> Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
> Service-Component: OSGI-INF/com.io7m.service0.provider_declarative.Speak
>  er.xml
> Tool: Bnd-3.2.0.201605172007
> -->8--
>
> The OSGI-INF/com.io7m.service0.provider_declarative.Speaker.xml descriptor
> inserted into the jar by the Maven plugin looks correct to me:
>
> --8<--
> <?xml version="1.0" encoding="UTF-8"?>
> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0";
> name="com.io7m.service0.provider_declarative.Speaker" activate="onActivate">
>   <implementation class="com.io7m.service0.provider_declarative.Speaker"/>
>   <service>
>     <provide interface="com.io7m.service0.api.SpeakerType"/>
>   </service>
> </scr:component>
> -->8--
>
> However, when installing and starting the bundle, I get nothing:
>
> g! install
> service0-provider-declarative/target/service0-provider-declarative-0.1.0.jar
> Bundle ID: 5
> g! start 5
> DEBUG: WIRE: [com.io7m.experimental.service0-provider-declarative [5](R
> 5.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.8)) ->
> [org.apache.felix.framework [0](R 0)]
> g! lb
> START LEVEL 1
>    ID|State      |Level|Name
>     0|Active     |    0|System Bundle (5.4.0)|5.4.0
>     1|Active     |    1|Apache Felix Bundle Repository (2.0.6)|2.0.6
>     2|Active     |    1|Apache Felix Gogo Command (0.16.0)|0.16.0
>     3|Active     |    1|Apache Felix Gogo Runtime (0.16.2)|0.16.2
>     4|Active     |    1|Apache Felix Gogo Shell (0.10.0)|0.10.0
>     5|Active     |    1|service0-provider-declarative (0.1.0)|0.1.0
>
> Am I missing something here? Why are none of the Speaker methods called?
>
> M
>
>

Reply via email to