OSGi NPE bei deklarativen Bundle mit Maven SCR

FilterPunk

Mitglied
Ich bin OSGi Anfänger und versuche mich an einem Beispielcose ähnlich diesem Tutorial.

Hie ist der Code (habe den Code der Netbeans-Projekte auch angehängt)

1.) Netbeans Maven OSGi Bundle Project "MavenHelloService OSGi Bundle"
1.a) Interface HelloService.java in com.joerg.mavenhelloservice.api
Java:
     public interface HelloService {
          public String sayHello(String name);
     }

1.b) Installer.java
Java:
      public class Installer implements BundleActivator {
          @Override
           public void start(BundleContext context) throws Exception {
               String userName = context.getProperty("user.name");
               System.out.println("User Name: " + userName);
           }
      …

1.c) Implematation HelloImpl.java
Java:
      public class Installer implements BundleActivator {
          @Component(name="hello-service")
          @Service
          public class HelloImpl implements HelloService {
              @Override
              public String sayHello(String name) {
                  return "Hello " + name;
              }
          }


2.) Netbeans Maven OSGi Bundle Project "HelloClient OSGi Bundle"
2.a) Activator.java
Java:
      @Component(name="hello-service-consumer")
      public class Activator implements BundleActivator {
          @Reference
          private HelloService helloService;
          @Override
          public void start(BundleContext context) throws Exception {
              System.out.println(helloService.sayHello("Duke"));
          }
     …

3.) The Maven SCR Plugins generates following XML Files in the jars.
3.a) In MavenHelloService-1.0-SNAPSHOT.jar serviceComponents.xml:
[XML]<?xml version="1.0" encoding="UTF-8"?><components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
<scr:component enabled="true" name="hello-service">
<implementation class="com.joerg.mavenhelloservice.HelloImpl"/>
<service servicefactory="false">
<provide interface="com.joerg.mavenhelloservice.api.HelloService"/>
</service>
<property name="service.pid" value="hello-service"/>
</scr:component>
</components>[/XML]
3.b) In HelloClient-1.0-SNAPSHOT.jar serviceComponents.xml:
[XML]<?xml version="1.0" encoding="UTF-8"?><components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
<scr:component enabled="true" name="hello-service-consumer">
<implementation class="com.joerg.helloclient.Activator"/>
<property name="service.pid" value="hello-service-consumer"/>
<reference name="helloService" interface="com.joerg.mavenhelloservice.api.HelloService" cardinality="1..1" policy="static" bind="bindHelloService" unbind="unbindHelloService"/>
</scr:component>
</components>[/XML]

I use following software versions:
Netbeans 7.2 on Mac OS X 10.8.1 with Oracle Java 1.7.0_06 (64bit)
Maven 4.17.1 (installed with Netbeans)
Apache Felix Framework 3.0.7 (as Dependency for Service and Client)
Apache Felix Annotations 1.6.0 (as Dependency for Service and Client)
Maven SCR Plugin 1.7.4 (added to pom.xml for Service and Client)
Apache Felix Framework 4.0.3 (on Terminal as OSGi playground)

In Terminal I start felix "java -jar /bin/felix.jar" and install+start bundles:
start file:/Volumes/workspace/MavenHelloService/target/MavenHelloService-1.0-SNAPSHOT.jar
start file:/Volumes/workspace//HelloClient/target/HelloClient-1.0-SNAPSHOT.jar

When starting the HelloClient I get:
java.lang.NullPointerException
at com.joerg.helloclient.Activator.start(Activator.java:17)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1977)

Where Activator.java:17 is: System.out.println(helloService.sayHello("Duke"));

Am I missing anything? Or are my scr declarations wrong?
 

Anhänge

  • osgi.zip
    35,2 KB · Aufrufe: 0
M

maki

Gast
nun, dann wird "helloService" hier wohl NULL sein ...... ;)
Schon mal den Debugger angeworfen ???:L
Hi,

dieser Rat ist nutzlos, das ist jedem klar der schon mal mit OSGi + DS gearbeitet hat ;)

@TS
Ein Bundleactivator gleichzeitig zu einer Komponente zu erheben kann gar nicht gehen, steht auch so nirgends im Beispiel ;)

Mach doch mal ein Interface + eine Implementierung und nutze das als deklerativen Service.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
I OSGi JUnit Plug'in Tests von deklarativen Services Plattformprogrammierung 5
T OSGi OSGI bundle bauen org.apache.xerces Plattformprogrammierung 3
H !MESSAGE Missing required bundle javax.mail_1.4.0. Plattformprogrammierung 5
G OSGi Bundle-ClassPath Plattformprogrammierung 3
G OSGi Ressourcen aus anderem Bundle laden Plattformprogrammierung 15
G RCP Datei im Bundle Plattformprogrammierung 6
A RCP RAP-Bundle nach Installation nicht auffindbar?! Plattformprogrammierung 5
A OSGi Bundle exportieren, importieren und vewenden geht nicht?! Plattformprogrammierung 4
lumo RCP The System Bundle was updated Plattformprogrammierung 13
A RCP p2 - manuelles update "check for updates" von core bundle funktioniert nicht Plattformprogrammierung 6
musiKk OSGi Bundle findet Activator nicht (ClassNotFoundException) Plattformprogrammierung 1
S OSGi Ablegen von Bundle-Eigenschaften (unabhängig) Plattformprogrammierung 4
L RCP Plugin als Bundle geklarieren? Plattformprogrammierung 3
O Bundle in Projekt-Dependencies nicht sichtbar Plattformprogrammierung 6
lumo Bundle verzeichnis Plattformprogrammierung 10
G [osgi] bundle spezifische properties Plattformprogrammierung 5
C RCP Applikation starten als OSGi Bundle Plattformprogrammierung 2
B OSGi, Euqinox, innherhalb vom Bundle Pfad des zugehörigen jar-files ermitteln Plattformprogrammierung 6
N bundle und classpath Plattformprogrammierung 12
Z MySQL-Treiber in RAP-Anwendung für Jetty im OSGI- Equinox- Maven-Dschungel Plattformprogrammierung 0
J Maven löst Zertifikatspfad bei HTTPS zum Repository-Server NEXUS nicht auf Plattformprogrammierung 1
P OSGi Maven build startet nicht <Unable to process "BundleTranslationProvider.locale"> Plattformprogrammierung 0
S Maven "mvn" funktioniert nicht Plattformprogrammierung 1
E Maven wird nicht mehr gefunden Plattformprogrammierung 3
R Verwendung pdfbox in Maven-Projekt in Eclipse Plattformprogrammierung 3
H OSGI mit Eclipse und Maven Plattformprogrammierung 5
S Maven Installation unter Windows 7 Plattformprogrammierung 10

Ähnliche Java Themen

Neue Themen


Oben