0

我使用 Apache Felix 来实现 osgi bundle 并将其用作嵌入式 Felix 框架来调用 boundle

这是我构建 MANIFEST.MF 的 Maven 插件:

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

我构建项目,然后像这样在嵌入的 felix 中使用 jar 文件

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();

当我开始boundle时,我遇到了这个异常

线程“主”org.osgi.framework.BundleException 中的异常:无法解析 abc [1](R 1.0):缺少要求 [abc [1](R 1.0)] osgi.wiring.package; (&(osgi.wiring.package=com.google.common.base)(version>=21.0.0)(!(version>=22.0.0))) 未解决的要求:[[abc [1](R 1.0) ] osgi.wiring.package; (&(osgi.wiring.package=com.google.common.base)(version>=21.0.0)(!(version>=22.0.0)))]

我应该怎么做才能解决这个问题?

4

1 回答 1

4

此错误消息意味着您的包依赖于 Google Guava,版本 21。特别是这一行:

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

... 意味着您的包“abc”导入com.google.common.base版本大于或等于 21 且不大于或等于 22 的包。由于您的包导入此包,因此必须有另一个包导出包的 OSGi 框架。

解决方案是确保将 Guava 21 安装到您的 OSGi 框架中。

于 2018-02-06T21:56:14.513 回答