[英]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.