0

i use Apache Felix to implement osgi bundle and use it as embedded Felix framework to call boundle

here is my maven plugin to build MANIFEST.MF :

<plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>3.5.0</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
                    <Bundle-Activator>a.b.c.osgi.activator.Activator</Bundle-Activator>
                </instructions>
            </configuration>
        </plugin>

i build project and then use jar file in embeded felix like this

BundleContext bundleContext = f.getBundleContext();
    Bundle bundle = bundleContext.installBundle(
            "file:/home/eclipse_workSpace/my-module/target/abc-1.1.0.jar");)

    String bName = bundle.getLocation();
    bundle.getRegisteredServices();
    bundle.getState();

    /* Bundle[] bls = bundleContext.getBundles(); */

    System.out.println("starting bundle " + bName);
    bundle.start();

when i start boundle i got this exception

Exception in thread "main" org.osgi.framework.BundleException: Unable to resolve a.b.c [1](R 1.0): missing requirement [a.b.c [1](R 1.0)] osgi.wiring.package; (&(osgi.wiring.package=com.google.common.base)(version>=21.0.0)(!(version>=22.0.0))) Unresolved requirements: [[a.b.c [1](R 1.0)] osgi.wiring.package; (&(osgi.wiring.package=com.google.common.base)(version>=21.0.0)(!(version>=22.0.0)))]

what should i do to solve this problem?

Ahmad R. Nazemi
  • 775
  • 10
  • 26

1 Answers1

4

This error message means that your bundle depends on Google Guava, version 21. Specifically this line:

missing requirement [a.b.c [1](R 1.0)] osgi.wiring.package; (&(osgi.wiring.package=com.google.common.base)(version>=21.0.0)(!(version>=22.0.0)))

... means that your bundle "a.b.c" imports the package com.google.common.base with version greater-than-or-equal to 21 and not-greater-than-or-equal to 22. Since your bundle imports this package, there must be another bundle in your OSGi Framework that exports the package.

The solution is to ensure that Guava 21 is installed into your OSGi Framework.

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • how can i install this package in OSGI Framework? is my pom config in maven-bundle-plugin is correct? is this installation should be automated by maven-bundle-plugin in MANIFEST.MF? – Ahmad R. Nazemi Feb 07 '18 at 09:39
  • You install it in the same way that you installed your first bundle. According to the code sample, you installed it by calling `bundleContext.installBundle`. – Neil Bartlett Feb 07 '18 at 13:20