使用另一个 OSGi bundle中的类



我在OSGi捆绑包中遇到了一个奇怪的问题。

我有两个捆绑包,比如说B1B2. B1导出包含类名的包a.b.cFoo方法:

public JsonNode helloWorld() {
    System.out.println("Hello World!");
    return null;
}

然后B2导入B1包并尝试使用B1中的类Foo。我在编译方面没有问题,在 Felix 中启动捆绑包时,一切似乎都很好。

但是当调用B2使用 helloWorld 方法时,B2停止工作并且不要抛出任何错误!经过一些调试后,我认为方法的返回类型helloWorld是原因,如果我更改JsonNode String一切按预期工作。

为什么我的菲利克斯控制台没有出错?为什么当返回类型为 JsonNode 时我不能调用 helloWorld 方法?

感谢您的帮助!

编辑1:更多信息,以下方法执行完全相同的错误:

 public String helloWorld() {
     System.out.println("Hello World!");
     JsonNode test =  JsonNodeFactory.instance.objectNode();
     return test.asText();
 }

我在控制台中看到你好世界!然后什么都没有,没有错误,没有痕迹,就像程序选择在这里停止并等待一样!

编辑2:我在构建时有这个警告,我不知道它是否重要:

[WARNING] Bundle fr.aaa.ccc.bbbb:1.0.0 : Export javax.json,  has 1,  private references [javax.json.stream], 

警告删除,仍然得到相同的举止。

编辑3:我设法在我的控制台中出现错误,我想我已经关闭了,无法找出问题所在!!

Caused by: java.lang.LinkageError: 
loader constraint violation: 
when resolving interface method "a.b.c.FooInterface.welcome(Ljava/lang/String;)Lorg/codehaus/jackson/JsonNode;"
the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) 
of the current class, d/e/f/lasthope/Activator, 
and the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for the method's defining class, a/b/c/aa/bb/FooInterface,
have different Class objects for the type org/codehaus/jackson/JsonNode used in the signature
    at d.e.f.Activator.start(Activator.java:37)

我猜你在捆绑激活器中调用该方法。一个常见的问题是,例如启动方法中的异常不会被记录。因此,请尝试使用尝试捕获呼叫helloworld并打印或记录异常。

我认为 JsonNode 的问题在于捆绑包 B2 看不到该类或 B1 看不到不同的类。 确保两个捆绑包都导入 JsonNode 所在的包。

最新更新