【问题标题】:org.osgi import cannot be resolvedorg.osgi 导入无法解决
【发布时间】:2020-01-23 17:37:44
【问题描述】:

我正在尝试开始使用 OSGI 并创建一个基本包。

我在 Eclipse (2019-06) 中创建了一个带有激活器的包,并选择 Liberty 作为目标运行时(最终目标是创建一个 Liberty 扩展)

它工作正常,但是当我将它转换为 Maven 时,Eclipse 抱怨 org.osgi 包无法解析

我看到这个依赖被定义了:

<dependency>
  <groupId>net.wasdev.maven.tools.targets</groupId>
  <artifactId>liberty-target</artifactId>
  <version>19.0.0.9</version>
  <type>pom</type>
  <scope>provided</scope>
</dependency>

我尝试将其添加到 felix 插件中,但没有成功。

        <Import-Package>
            org.osgi.framework
        </Import-Package>

在尝试了一段时间之后,我准备放弃了。任何帮助将不胜感激。

【问题讨论】:

  • org.osgi 包无法在运行时或编译时解析?请注意,在 Maven 中,依赖项是静态解析的,而在 OSGi 中,捆绑包可以在运行时安装,因此依赖项也在运行时解析。

标签: eclipse maven osgi bundle websphere-liberty


【解决方案1】:

为 OSGi 规范添加这些 maven 依赖项。

    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>osgi.core</artifactId>
        <version>6.0.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>osgi.cmpn</artifactId>
        <version>6.0.0</version>
        <scope>provided</scope>
    </dependency>

您还必须配置 bnd-maven-plugin。所以你的进口是自动计算的。或者,您可以使用 maven-bundle-plugin。 (您可能已经在使用它了)。

<plugin>
    <groupId>biz.aQute.bnd</groupId>
    <artifactId>bnd-maven-plugin</artifactId>
    <version>4.2.0</version>
    <executions>
        <execution>
            <goals>
                <goal>bnd-process</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.1.0</version>
    <configuration>
        <archive>
           <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
        </archive>
    </configuration>
</plugin>

这涵盖了包的编译时解析。

此外,您还需要在运行时提供正确的捆绑包。这在很大程度上取决于您如何定义运行时。

一些 org.osgi 包来自 OSGi 框架本身。其他的必须作为捆绑包安装。请注意,您通常不会将规范安装为捆绑包。相反,您安装的实现也会带来规范。

【讨论】:

  • 谢谢!我想我希望转换更加自动化。我不得不更改测试类的输出目录: test_bin 这允许我右键单击,Maven > 更新项目。它从 liberty 目标依赖项中获取了 org.osgi。然后我添加了:org.osgi.service.component.annotations 谢谢!
猜你喜欢
  • 2017-05-12
  • 1970-01-01
  • 2021-11-20
  • 2013-03-11
  • 1970-01-01
  • 2019-02-12
  • 2021-09-13
  • 2020-12-16
  • 2014-09-04
相关资源
最近更新 更多