[英]How can I detect runtime libraries of an OSGi bundle if it uses classloader?
我正在尝试将复杂的应用程序(jForexAPi,DDS2)放入OSGi捆绑包。 我制作了两个具有嵌入式依赖项的捆绑包,它们都具有编译时和运行时(可传递)。 所以我在.jar捆绑包中有带有.class-es的捆绑包。
当我尝试使用ClassNotFoundException时,是因为DDS2实现在运行时通过其线程的类加载器加载类。 像这样:
Class e = Thread.currentThread().getContextClassLoader().loadClass("com.dukascopy.charts.main.DDSChartsControllerImpl");
我有两个问题:
如何确定karaf中线程的父包?
你不能。 线程没有父捆绑。 如果您是指Thread上下文类加载器,则OSGi中根本没有定义它。 TCC通常是Java EE世界中Web应用程序的类加载器。 但是,在OSGi中,它甚至可以为null或任何其他值。 永远不要使用它。
如何解决OSGi中的运行时类加载之类的问题? 有没有办法允许或发现运行时类加载?
您可以做两件事:
如果选择第二个选项,则代码将类似于以下内容:
Thread currentThread = Thread.currentThread();
ClassLoader previousCL = currentThread.getContextClassLoader();
try {
currentThread.setContextClassLoader(DDSChartsControllerImpl.class.getClassLoader());
callNextFunctionOnStacktrace();
} finally {
// You should set the original CL back as other technology might use the TCC tricks, too
currentThread.setContextClassLoader(previousCL);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.