[英]Use class from another OSGi bundle
我在OSGi捆绑软件中遇到了一个奇怪的问题。
我有两个捆绑包,比如说B1
和B2
。 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.