【问题标题】:Unresolved requirement: Import-Package: org.slf4j when starting bundle in Kura Emulator未解决的要求:在 Kura Emulator 中启动包时导入包:org.slf4j
【发布时间】:2018-05-25 11:02:30
【问题描述】:

大家好,

使用 Kura Linux 模拟器,我正在运行 Kura 文档中的 Hello World 示例 http://eclipse.github.io/kura/dev/deploying-bundles.html#remote-target-device

我设法在本地仿真模式下运行 OSGi 插件,这是 Kura Emulator Linux/java 日志的输出。

21:14:18,036 [Component Resolve Thread] INFO  HelloOsgi:15  - Bundle org.eclipse.kura.example.hello_osgi has started!

但是,当我尝试从控制台启动/停止捆绑包时,我只设法实现了安装步骤。 以下是安装后主机 OSGi 控制台的一些相关输出。

osgi> install file:/home/tihomir/workspace/kura/plugins/org.eclipse.kura.example.hello_osgi_1.0.0.201712111129.jar
Bundle id is 1020
LastModified         1513020115678
Headers               Bundle-ManifestVersion = 2
 Bundle-Name = Hello World Example with Logger
 Bundle-RequiredExecutionEnvironment = JavaSE-1.8
 Bundle-SymbolicName = org.eclipse.kura.example.hello_osgi
 Bundle-Version = 1.0.0.201712111129
 Import-Package = org.eclipse.osgi.framework.console;version="1.0.0",
org.osgi.framework;version="1.3.0",
org.osgi.service.component;version="1.2.2",
org.osgi.service.component.annotations;version="1.2.0";resolution:=optional,
org.osgi.util.tracker;version="1.3.1",org.4j;version="1.7.21"
 Manifest-Version = 1.0
 Service-Component = OSGI-INF/*.xml
Location             file:/home/tihomir/workspace/kura/plugins/org.eclipse.kura.example.hello_osgi_1.0.0.201712111129.jar
State                2
Bundle                1020|Installed  |    1|org.eclipse.kura.example.hello_osgi (1.0.0.201712111129)
Version              1.0.0.201712111129
RegisteredServices   null
ServicesInUse        null
Module               osgi.identity; osgi.identity="org.eclipse.kura.example.hello_osgi"; type="osgi.bundle"; version:Version="1.0.0.201712111129" [id=1020]
SymbolicName         org.eclipse.kura.example.hello_osgi
BundleContext        null
BundleId             1020


osgi> ss
"Framework is launched."
id  State       Bundle
0   ACTIVE      org.eclipse.osgi_3.12.50.v20170928-1321
                Fragments=1
997 RESOLVED    org.slf4j.api_1.7.2.v20121108-1250
                Fragments=5, 998
998 RESOLVED    org.slf4j.impl.log4j12_1.7.2.v20131105-2200
                Master=997
1020    INSTALLED   org.eclipse.kura.example.hello_osgi_1.0.0.201712111129

但是现在,当我尝试激活捆绑包时,尽管上面的输出显示 org.slf4j 已解决,但我得到以下异常

osgi> start 1020
gogo: BundleException: Could not resolve module: org.eclipse.kura.example.hello_osgi [1020]
  Unresolved requirement: Import-Package: org.slf4j; version="1.7.21"

我在 Debian 9 上运行模拟器。 这也是插件清单

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Hello World Example with Logger
Bundle-SymbolicName: org.eclipse.kura.example.hello_osgi
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Service-Component: OSGI-INF/*.xml
Import-Package: org.eclipse.osgi.framework.console;version="1.0.0",
 org.osgi.framework;version="1.3.0",
 org.osgi.service.component;version="1.2.2",
 org.osgi.service.component.annotations;version="1.2.0";resolution:=optional,
 org.osgi.util.tracker;version="1.3.1",
 org.slf4j;version="1.7.21"

已经尝试了一些我在此处和 Eclipse 论坛上找到的检查/修复,但没有任何效果,因此欢迎提出任何新的建议。

【问题讨论】:

    标签: java eclipse osgi slf4j kura


    【解决方案1】:

    编辑项目的 POM 并降级 SLF4j,因为 Kura 似乎提供 SLF4j v 1.7。2,而您的捆绑包至少需要 v 1.7。21


    根据@NeilBartlett 的评论,启动 SLF4j 捆绑包不需要解决捆绑包的依赖关系。如果您没有看到任何来自您的包的日志行,我将这部分答案留在这里作为提醒。

    SLF4j 包未启动(ss 显示它们处于 RESOLVED 状态)。尝试使用start 997 998 启动它们。

    【讨论】:

    • 解析包不需要启动捆绑包,因此请点击第一段。第二段似乎是实际的解决方案。
    • 谢谢@NeilBartlett 我相应地更新了我的答案。我不知道 Kura 模拟器如何处理日志引擎。我不知道org.slf4j.impl.log4j12是否必须开始,所以我选择保留第一段作为附录。
    • Slf4j 绝对不需要启动。它不包含特定于 OSGi 的激活器,因此如果您尝试启动它,它可能无能为力。另一方面,启动捆绑包从来没有真正受到伤害。
    【解决方案2】:

    您的Import-Package 范围总体上看起来是错误的。例如你有这个:

    Import-Package: org.slf4j;version="1.7.21"
    

    首先:不需要指定微段(即最后一个段,21)。微型版本表示错误修复、性能改进、文档更改等。这些都不会对您作为消费者产生任何语义影响。因此,您应该只从版本 1.7 导入,因为低于该版本的任何微版本都将与您的代码兼容。

    第二:您的导入范围没有上限!这意味着您将从版本1.7.21 或任何更高版本 导入,直到无穷大。因此,尽管您对范围的底端非常敏感,但您对高端却非常无忧无虑!你应该限制范围如下:

    Import-Package: org.slf4j; version="[1.7,2.0)"
    

    这允许您的包导入最高版本 1.7 但不包括 Slf4j 版本 2.0(如果曾经存在)。这是正确的,因为版本 2 表明 Slf4j API 发生了重大变化。

    对所有其他导入的建议相同:

    Import-Package: org.osgi.framework;version="[1.3, 2.0)",
      org.osgi.service.component;version="[1.2, 2.0)",
      ... etc
    

    如果您使用bnd 或其衍生工具之一来生成清单,您无需考虑任何这些,一切都会正确。

    【讨论】:

      【解决方案3】:

      感谢@NeilBartlett @AlessandroDaRugna

      事实证明,该示例毕竟按预期工作。 问题是要弄清楚文档中指的是哪个控制台,因为在 Eclipse IDE 中,您可以在两个选项之间进行选择。 Kura Emulator Linux/java 控制台,显然是说明中的一个,对用户不是很友好,需要一些时间来适应。 另一个控制台,Host OSGi,我真的想不通,但它似乎与模拟器解耦,可能是一种通用接口。

      再次感谢您的支持。

      【讨论】:

        猜你喜欢
        • 2021-03-04
        • 1970-01-01
        • 2019-04-12
        • 2017-12-23
        • 1970-01-01
        • 2017-12-19
        • 1970-01-01
        • 2014-08-28
        • 2018-07-21
        相关资源
        最近更新 更多