Apache Felix OSGi错误:缺少要求osgi.extender

时间:2019-01-03 10:47:41

标签: java maven osgi apache-felix

尝试启动捆绑包时出现此错误:

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)))]

我的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>

代码:

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;
    }
}

我在做什么错了?

谢谢

1 个答案:

答案 0 :(得分:3)

您的捆绑包包含一个声明式服务组件-代码中的FacadeLocator。这意味着您依赖于实现声明式服务的“扩展器”捆绑包。您需要将该捆绑包与自己的捆绑包一起部署,以使其正常工作。

Apache Felix的DS实施捆绑包的名称为org.apache.felix.scr,可以下载from Maven Central

可以将您看到的错误消息解码如下。 osgi.extender名称空间(扩展程序的名称空间类似于DS)中缺少要求。您需要的特定扩展程序是osgi.component,版本1.3或更高版本。 Maven-bundle-plugin在捆绑软件的META-INF / MANIFEST.MF中生成了此要求,因为它看到捆绑软件中包含组件。每当捆绑包具有需求时,都必须有另一个捆绑包提供匹配的 capability 。在这种情况下,该捆绑包为org.apache.felix.scr