【问题标题】:Caused by: java.lang.NoClassDefFoundError: org/osgi/framework/BundleActivator: when importing multiple packages引起:java.lang.NoClassDefFoundError: org/osgi/framework/BundleActivator: 导入多个包时
【发布时间】:2018-02-19 06:19:11
【问题描述】:

我正在尝试来自 apache felix 的 OSGi 示例

第一个和第二个示例安装并开始正常。但是第三个示例中存在与 osgi 的依赖关系并且之前安装的服务失败并出现 class not found 错误。

清单.MF

Manifest-Version: 1.0 
Bundle-ManifestVersion: 2 
Bundle-Name: French dictionary
Bundle-SymbolicName: fr-dict
Bundle-Description: A bundle that registers a French dictionary service
Bundle-Vendor: Apache Felix
Bundle-Version: 1.0.0
Bundle-Activator: tutorial.example2b.Activator
Import-Package: org.osgi.framework, 
 tutorial.example2.service

注意:我在最后一行之后换了一个新行。

g! start file:/Users/johne/Desktop/bundle-dict-fr.jar                                                                                                                                                                    10:18:39
org.osgi.framework.BundleException: Activator start error in bundle fr-dict [11].
    at org.apache.felix.framework.Felix.activateBundle(Felix.java:2289)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2145)
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)
    at org.apache.felix.gogo.command.Basic.start(Basic.java:739)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.felix.gogo.runtime.Reflective.invoke(Reflective.java:136)
    at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:91)
    at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:571)
    at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:497)
    at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:386)
    at org.apache.felix.gogo.runtime.Pipe.doCall(Pipe.java:417)
    at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:229)
    at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:59)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: org/osgi/framework/BundleActivator
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.defineClass(BundleWiringImpl.java:2375)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2159)
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1578)
    at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1404)
    at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4505)
    at org.apache.felix.framework.Felix.activateBundle(Felix.java:2220)
    ... 19 more
Caused by: java.lang.ClassNotFoundException: org.osgi.framework.BundleActivator not found by fr-dict [11]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1610)
    at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 30 more
java.lang.NoClassDefFoundError: org/osgi/framework/BundleActivator

这是 lb 之后的输出,

g! lb                                                                                                                                                                                                                    10:19:40
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (5.6.8)|5.6.8
    1|Active     |    1|jansi (1.16.0)|1.16.0
    2|Active     |    1|JLine Bundle (3.3.0)|3.3.0
    3|Active     |    1|Apache Felix Bundle Repository (2.0.10)|2.0.10
    4|Active     |    1|Apache Felix Gogo Command (1.0.2)|1.0.2
    5|Active     |    1|Apache Felix Gogo JLine Shell (1.0.6)|1.0.6
    6|Active     |    1|Apache Felix Gogo Runtime (1.0.6)|1.0.6
    7|Active     |    1|Service listener example (1.0.0)|1.0.0
    8|Active     |    1|English dictionary (1.0.0)|1.0.0
   11|Resolved   |    1|French dictionary (1.0.0)|1.0.0

【问题讨论】:

  • 您的 MANIFEST.MF 是否以换行符结尾?
  • 你能把你用来启动的命令行加进去吗?
  • g! start file:/Users/johne/Desktop/bundle-dict-fr.jar

标签: osgi classnotfoundexception apache-felix


【解决方案1】:

两个导入的包之间有一个换行符:

Import-Package: org.osgi.framework, 
tutorial.example2.service

你能不能把两者放在同一行:

Import-Package: org.osgi.framework, tutorial.example2.service

我猜在您当前的 Manifest 中, Import-Package 被忽略,因为语法无效。所以你的包可以很好地解析,但不会导入任何包。当激活器运行时,它找不到任何外部类。

【讨论】:

  • 如果您的导入正确,则不应发生此错误。你的 jar 中的 Manifest 现在包含什么?
  • 这就是为什么我询问 MANIFEST.MF 是否有尾随换行符。这在清单格式中是必需的,如果最后一个条目不存在,则可能无法正确读取。
  • 是的,我在最后有一个新行。 :-|。请注意,这是 Felix 文档中的第三个示例。第 1 次和第 2 次运行良好。只有在这个例子中,我们有多个导入。
  • 确实 .. 该教程准确显示了您发布的清单。如果我看到同样的问题,我会自己尝试这个例子并报告。顺便提一句。不建议在没有任何其他工具的情况下使用 felix。有两种很好的替代环境可以让您更快地上手。 bndtools 和 Apache Karaf。我建议从那里的教程之一开始。
  • @ChristianSchneider 非常感谢。让我知道您是否能够重现该错误。同时我会看看卡拉夫
【解决方案2】:

我遇到了同样的问题,我通过重写 Import-Package 行来解决它。最初我复制粘贴了清单文件,因此其中可能存在一些非法字符。

【讨论】:

    猜你喜欢
    • 2017-10-02
    • 2022-01-27
    • 1970-01-01
    • 2016-12-11
    • 2016-08-11
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    相关资源
    最近更新 更多