Apache PDFBox 和 CodenameOne 桌面应用程序

Apache PDFBox and CodenameOne Desktop app

我有一个 CodenameOne 项目已经基本完成,我需要将桌面版与 PDFBox 集成。我正在尝试打开文档并将页面呈现为我在应用程序中显示的图像。

我收到以下错误:

java.lang.NoClassDefFoundError: Could not initialize class org.apache.pdfbox.pdmodel.font.PDTrueTypeFont
    at org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:100)
    at org.apache.pdfbox.pdmodel.PDResources.getFonts(PDResources.java:213)
    at org.apache.pdfbox.util.PDFStreamEngine.getFonts(PDFStreamEngine.java:607)
    at org.apache.pdfbox.util.operator.SetTextFont.process(SetTextFont.java:59)
    at org.apache.pdfbox.util.PDFStreamEngine.processOperator(PDFStreamEngine.java:557)
    at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:268)
    at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:235)
    at org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:215)
    at org.apache.pdfbox.pdfviewer.PageDrawer.drawPage(PageDrawer.java:139)
    at org.apache.pdfbox.pdmodel.PDPage.convertToImage(PDPage.java:801)
    at co.za.gingetsuryuu.pdfreader.PDFInterfaceImpl.run(PDFInterfaceImpl.java:69)
    at java.lang.Thread.run(Thread.java:745)
java.lang.NoClassDefFoundError: Could not initialize class org.apache.pdfbox.pdmodel.font.PDTrueTypeFont
    at org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:100)
    at org.apache.pdfbox.pdmodel.PDResources.getFonts(PDResources.java:213)
    at org.apache.pdfbox.util.PDFStreamEngine.getFonts(PDFStreamEngine.java:607)
    at org.apache.pdfbox.util.operator.SetTextFont.process(SetTextFont.java:59)
    at org.apache.pdfbox.util.PDFStreamEngine.processOperator(PDFStreamEngine.java:557)
    at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:268)
    at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:235)
    at org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:215)
    at org.apache.pdfbox.pdfviewer.PageDrawer.drawPage(PageDrawer.java:139)
    at org.apache.pdfbox.pdmodel.PDPage.convertToImage(PDPage.java:801)
    at co.za.gingetsuryuu.pdfreader.PDFInterfaceImpl.run(PDFInterfaceImpl.java:69)
    at java.lang.Thread.run(Thread.java:745)
java.lang.NoClassDefFoundError: Could not initialize class org.apache.pdfbox.pdmodel.font.PDTrueTypeFont
    at org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:100)
    at org.apache.pdfbox.pdmodel.PDResources.getFonts(PDResources.java:213)
    at org.apache.pdfbox.util.PDFStreamEngine.getFonts(PDFStreamEngine.java:607)
    at org.apache.pdfbox.util.operator.SetTextFont.process(SetTextFont.java:59)
    at org.apache.pdfbox.util.PDFStreamEngine.processOperator(PDFStreamEngine.java:557)
    at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:268)
    at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:235)
    at org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:215)
    at org.apache.pdfbox.pdfviewer.PageDrawer.drawPage(PageDrawer.java:139)
    at org.apache.pdfbox.pdmodel.PDPage.convertToImage(PDPage.java:801)
    at co.za.gingetsuryuu.pdfreader.PDFInterfaceImpl.run(PDFInterfaceImpl.java:69)
    at java.lang.Thread.run(Thread.java:745)

我完全不知所措。我已经检查了库是否包含在内,它设法呈现了一个或两个页面,但仅此而已。我什至检查过该函数确实存在,它确实存在。

你把PDF盒子API的jar包放在native/javase文件夹下了吗?否则,jar 将不会发送到构建服务器,也不会打包为应用程序的一部分。

问题似乎与代号一号执行构建过程的方式有关。通过在结果项目中包含 jar 文件并使它们在 jar 加载顺序中的加载顺序高于 app.jar 文件,问题得到解决。