Apache Felix OSGi error: missing requirement osgi.extender
Asked Answered
M

3

5

I'm getting this error when attempting to start a bundle:

org.osgi.framework.BundleException:
  Unable to resolve com.example.test [7](R 7.0):
    missing requirement [com.example.test [7](R 7.0)] osgi.extender; (&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))
  Unresolved requirements:
    [[com.example.test [7](R 7.0)] osgi.extender; (&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))]

My pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>bundle</packaging>

    <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>6.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.service.component.annotations</artifactId>
            <version>1.4.0</version>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <version>4.0.0</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <configuration>
                    <instructions>
                        <Export-Package>com.example</Export-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Code:

Facade.java:

package com.example;
public interface Facade {}

FacadeLocator.java:

package com.example;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

@Component
public class FacadeLocator {
    public static Facade facade;

    @Reference
    public void setFacade(Facade facade) {
        FacadeLocator.facade = facade;
    }
}

What am I doing wrong?

Thank you

Marcellusmarcelo answered 3/1, 2019 at 10:47 Comment(0)
W
10

Your bundle contains a Declarative Services component -- FacadeLocator from your code. This means you have a dependency on the "extender" bundle that implements Declarative Services. You need to deploy that bundle alongside your own bundle in order for it to work.

The DS implementation bundle from Apache Felix has the name org.apache.felix.scr and it can be downloaded from Maven Central.

The error message you saw can be decoded as follows. You have a missing requirement in the osgi.extender namespace, (the namespace for extenders similar to DS). The specific extender you require is osgi.component, version 1.3 or above. The maven-bundle-plugin generated this requirement in your bundle's META-INF/MANIFEST.MF because it saw your bundle has a component in it. Whenever a bundle has a requirement, there must be another bundle that provides a matching capability. In this case, that bundle is org.apache.felix.scr.

Wareing answered 3/1, 2019 at 13:34 Comment(3)
Thank you so much!Soil
@MartinHeralecký By the way, saving the service reference into a static field is a really bad idea!Wareing
you can read about similar issue in this question #40791043Bustee
B
1

in karaf install the feature Declarative Service Support by using this cmd feature:install scr

Barbabas answered 4/2, 2022 at 13:15 Comment(0)
V
0

I had to download and add the following dependency to the target definition:

<!-- https://mvnrepository.com/artifact/org.apache.aries.spifly/org.apache.aries.spifly.dynamic.bundle -->
<dependency>
    <groupId>org.apache.aries.spifly</groupId>
    <artifactId>org.apache.aries.spifly.dynamic.bundle</artifactId>
    <version>1.3.7</version>
</dependency>
Vella answered 9/9 at 10:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.