【发布时间】:2015-01-21 10:43:55
【问题描述】:
我在使用 OSGi 包时遇到了一个奇怪的问题。
我有两个包,比如说B1 和B2。
B1 导出包a.b.c,其中包含一个类名Foo 和一个方法:
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!然后什么都没有,没有错误,没有痕迹,就像程序选择在这里停下来等待一样!
编辑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)
【问题讨论】:
-
请发布 StackTrace。
-
正如所说,根本没有堆栈跟踪。我在调用 helloWorld 方法之前和之后放置了一条日志消息。第一条日志消息出现在控制台中,但第二条从未出现。没有错误,没有堆栈跟踪,什么都没有>