繁体   English   中英

使用另一个OSGi捆绑包中的类

[英]Use class from another OSGi bundle

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

我有两个捆绑包,比如说B1B2 B1使用以下方法导出包含类名称Foo的包abc

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

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

但是,当调用B2使用helloWorld方法时, B2停止工作并且不引发任何错误! 经过一些调试后,我发现方法helloWorld的返回类型是原因,如果我将JsonNode更改为String一切正常。

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

感谢帮助 !

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

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

我在控制台中看到了Hello World! 然后什么也没有,没有错误,没有跟踪,就像程序选择在此处停止并等待!

Edit2: 构建时出现此警告,我不知道这是否重要:

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

警告删除,仍然得到相同的称呼。

Edit3:我设法在控制台中出现错误,我认为我已经关闭以找出问题所在!

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)

我猜您在BundleActivator中调用了该方法。 常见的问题是未记录例如start方法中的异常。 因此,请尝试使用try catch处理对helloworld的调用,并打印或记录异常。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM