我正在嘗試在運(yùn)行時(shí)從模塊化 java 11 應(yīng)用程序加載和訪問 libreoffice uno jar。為了在編譯時(shí)使用 libreoffice 類并避免拆分包的問題,我們將所有 jar 合并到一個(gè)具有自動(dòng)模塊名稱的單獨(dú)的org.jabref.thirdparty.libreofficejar 中。要從 libreoffice 安裝目錄加載 jar(例如,C:\Program Files\LibreOffice\program\classes為了確保從程序文件而不是從我的模塊路徑加載 jar,我創(chuàng)建了一個(gè)自定義類加載器。 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():現(xiàn)在這給了我以下錯(cuò)誤: 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')我確實(shí)理解這里的問題并閱讀了很多有關(guān)此問題的內(nèi)容,但找不到解決此問題的方法。關(guān)鍵問題是我必須使用 LO 文件夾中的 jar,否則它將找不到 libreoffice 實(shí)例。我考慮過將模塊化 jar 也放入 LO 文件夾中,但不確定這是否可行。在 Java 8 下,我們使用典型的“reflection + addUrls”方法,因?yàn)樗袃?nèi)容都在類路徑上。
1 回答

30秒到達(dá)戰(zhàn)場
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超6個(gè)贊
從 LibreOffice 7.0 開始,現(xiàn)在有一個(gè)與 Java 模塊系統(tǒng)一起使用的組合 libreoffice.jar。
添加回答
舉報(bào)
0/150
提交
取消