2

I'm new in Apache Felix. I'm trying to create a bundle for implementing the configurarion admin. These are my two class of my project:

Activator.java

public void start(BundleContext context) throws Exception {
    Hashtable<String, String> prop = new Hashtable<String, String>();
    prop.put("Message", "Ciao");

    System.out.println("Prova");

    context.registerService(ManagedService.class.getName(), new Configuration(), prop);
}

public void stop(BundleContext context) throws Exception {
    //The service will be unregistered automatically
}

Configuration.java

private String msg = "";

public void updated(Dictionary prop) {
    if(prop == null) {
        System.out.println("Configuration reset");
        msg = null;
    }
    else {
        msg = (String)prop.get("Message");
        System.out.println("Configuration set. Message: " + msg);
    }
}

These are my pom.xml dependencies:

<dependency>
    <groupId>org.osgi</groupId>
    <artifactId>org.osgi.compendium</artifactId>
    <version>${org.osgi.compendium.version}</version>
    <scope>compile</scope>
  </dependency>
  <dependency>
    <groupId>org.osgi</groupId>
    <artifactId>org.osgi.core</artifactId>
    <version>${org.osgi.core.version}</version>
    <scope>compile</scope>
  </dependency>

these are my pom.xml plugins:

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.5.3</version>
    <extensions>true</extensions>
    <configuration>
        <supportedProjectTypes>
            <supportedProjectType>jar</supportedProjectType>
            <supportedProjectType>bundle</supportedProjectType>
            <supportedProjectType>war</supportedProjectType>
        </supportedProjectTypes>
        <instructions>
            <Bundle-ManifestVersion>2</Bundle-ManifestVersion>
            <Bundle-Name>${project.name}</Bundle-Name>
            <Bundle-SymbolicName>${project.artifactId};singleton:=true</Bundle-SymbolicName>
            <Bundle-Version>${project.version}</Bundle-Version>
            <Bubdle-Activator>org.apache.felix.conf.Activator</Bubdle-Activator>
            <Bundle-Vendor>FINO</Bundle-Vendor>
            <Import-Package>
                org.osgi.framework,
                org.osgi.service.cm
            </Import-Package>
        </instructions>
    </configuration>
</plugin>

When i execute my project in the apache felix framework 5.0.1 with terminal i get this error:

org.osgi.framework.BundleException: Unable to resolve org.apache.felix.conf [34](R 34.6): 
    missing requirement [org.apache.felix.conf [34](R 34.6)] osgi.wiring.package; 
        (&(osgi.wiring.package=org.osgi.service.cm)(version>=1.3.0)(!(version>=2.0.0))) 
    Unresolved requirements: [[org.apache.felix.conf [34](R 34.6)] osgi.wiring.package; 
        (&(osgi.wiring.package=org.osgi.service.cm)(version>=1.3.0)(!(version>=2.0.0)))]

I have also tryed to follow the solution of this stackoverflow article Karaf / Maven - Unable to resolve: missing requirement osgi.wiring.package but it talk about apache karaf not felix. Please help me

UPDATE

This is my MANIFEST.MF:

    Manifest-Version: 1.0
    Bnd-LastModified: 1438261057801
    Build-Jdk: 1.7.0_79
    Built-By: apache
    Bundle-Description: A maven project that implements apache felix
    Bundle-ManifestVersion: 2
    Bundle-Name: ServerConfig
    Bundle-SymbolicName:tutorials.fino.apachefelix.org.apachefelix.serverco
     nf
    Bundle-Version: 0.0.1.SNAPSHOT
    Created-By: Apache Maven Bundle Plugin
    Export-Package: org.apachefelix.serverconf;version="0.0.1";uses:="org.os
     gi.framework,org.osgi.service.cm"
    Import-Package: org.osgi.framework;version="[1.7,2)",org.osgi.service.cm
     ;version="[1.5,2)"
    Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.5))"
    Tool: Bnd-2.3.0.201405100607
Community
  • 1
  • 1
user3402649
  • 121
  • 1
  • 3
  • 15
  • 1
    There's a typo in `....` And not that this is the reason but [`BundleContext.registerService()`](https://osgi.org/javadoc/r4v43/core/org/osgi/framework/BundleContext.html#registerService%28java.lang.Class,%20S,%20java.util.Dictionary%29) takes also just a `Class` not only a `String.` – Gerold Broser Jul 29 '15 at 20:01
  • Thanks. But after that I have fixed these errors i have always the same problem. Do you know why? – user3402649 Jul 30 '15 at 07:36
  • Can you add the `MANIFEST.MF` of the resulting bundle `jar.` – Gerold Broser Jul 30 '15 at 11:41
  • _"I have fixed these errors"_? Really? The [``](http://wiki.osgi.org/wiki/Bundle-Activator) header is missing. Did you build the bundle again after these fixes? – Gerold Broser Aug 02 '15 at 16:59

0 Answers0