我正在嘗試在運行時從模塊化 java 11 應用程序加載和訪問 libreoffice uno jar。為了在編譯時使用 libreoffice 類并避免拆分包的問題,我們將所有 jar 合并到一個具有自動模塊名稱的單獨的org.jabref.thirdparty.libreofficejar 中。要從 libreoffice 安裝目錄加載 jar(例如,C:\Program Files\LibreOffice\program\classes為了確保從程序文件而不是從我的模塊路徑加載 jar,我創建了一個自定義類加載器。 URL[] urls = jarUrls.toArray(new URL[3]); Class<Bootstrap> clazz = (Class<Bootstrap>) Class.forName("com.sun.star.comp.helper.Bootstrap", true, new ChildFirstClassLoader(urls, this.getClass().getClassLoader())); Boostrap boot = clazz.getDeclaredConstructor().newInstance(); XComponentContext xContext = boot.bootstrap():現在這給了我以下錯誤: java.lang.ClassCastException: class com.sun.star.comp.helper.Bootstrap cannot be cast to class com.sun.star.comp.helper.Bootstrap (com.sun.star.comp.helper.Bootstrap is in unnamed module of loader org.jabref.logic.openoffice.ChildFirstClassLoader @13c4b54c; com.sun.star.comp.helper.Bootstrap is in module org.jabref.thirdparty.libreoffice of loader 'app')我確實理解這里的問題并閱讀了很多有關此問題的內容,但找不到解決此問題的方法。關鍵問題是我必須使用 LO 文件夾中的 jar,否則它將找不到 libreoffice 實例。我考慮過將模塊化 jar 也放入 LO 文件夾中,但不確定這是否可行。在 Java 8 下,我們使用典型的“reflection + addUrls”方法,因為所有內容都在類路徑上。
添加回答
舉報
0/150
提交
取消