0

我有一个使用 Apache 的 PDFBox 的 JavaFX 项目。我想使用 JLink 来构建它的 JRE,但我不能,因为 PDFBox 是一个自动模块。因此,我试图在其中注入一个模块信息文件。

我使用 jdeps 生成了这个模块信息文件:

module org.apache.pdfbox {
    requires org.bouncycastle.pkix;
    requires org.bouncycastle.provider;

    requires transitive commons.logging;
    requires transitive java.desktop;
    requires transitive java.xml;
    requires transitive org.apache.fontbox;

    exports org.apache.pdfbox.contentstream;
    exports org.apache.pdfbox.contentstream.operator;
    exports org.apache.pdfbox.contentstream.operator.color;
    exports org.apache.pdfbox.contentstream.operator.graphics;
    exports org.apache.pdfbox.contentstream.operator.markedcontent;
    exports org.apache.pdfbox.contentstream.operator.state;
    exports org.apache.pdfbox.contentstream.operator.text;
    exports org.apache.pdfbox.cos;
    exports org.apache.pdfbox.filter;
    exports org.apache.pdfbox.io;
    exports org.apache.pdfbox.multipdf;
    exports org.apache.pdfbox.pdfparser;
    exports org.apache.pdfbox.pdfwriter;
    exports org.apache.pdfbox.pdmodel;
    exports org.apache.pdfbox.pdmodel.common;
    exports org.apache.pdfbox.pdmodel.common.filespecification;
    exports org.apache.pdfbox.pdmodel.common.function;
    exports org.apache.pdfbox.pdmodel.common.function.type4;
    exports org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure;
    exports org.apache.pdfbox.pdmodel.documentinterchange.markedcontent;
    exports org.apache.pdfbox.pdmodel.documentinterchange.prepress;
    exports org.apache.pdfbox.pdmodel.documentinterchange.taggedpdf;
    exports org.apache.pdfbox.pdmodel.encryption;
    exports org.apache.pdfbox.pdmodel.fdf;
    exports org.apache.pdfbox.pdmodel.font;
    exports org.apache.pdfbox.pdmodel.font.encoding;
    exports org.apache.pdfbox.pdmodel.graphics;
    exports org.apache.pdfbox.pdmodel.graphics.blend;
    exports org.apache.pdfbox.pdmodel.graphics.color;
    exports org.apache.pdfbox.pdmodel.graphics.form;
    exports org.apache.pdfbox.pdmodel.graphics.image;
    exports org.apache.pdfbox.pdmodel.graphics.optionalcontent;
    exports org.apache.pdfbox.pdmodel.graphics.pattern;
    exports org.apache.pdfbox.pdmodel.graphics.shading;
    exports org.apache.pdfbox.pdmodel.graphics.state;
    exports org.apache.pdfbox.pdmodel.interactive.action;
    exports org.apache.pdfbox.pdmodel.interactive.annotation;
    exports org.apache.pdfbox.pdmodel.interactive.annotation.handlers;
    exports org.apache.pdfbox.pdmodel.interactive.annotation.layout;
    exports org.apache.pdfbox.pdmodel.interactive.digitalsignature;
    exports org.apache.pdfbox.pdmodel.interactive.digitalsignature.visible;
    exports org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination;
    exports org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline;
    exports org.apache.pdfbox.pdmodel.interactive.form;
    exports org.apache.pdfbox.pdmodel.interactive.measurement;
    exports org.apache.pdfbox.pdmodel.interactive.pagenavigation;
    exports org.apache.pdfbox.pdmodel.interactive.viewerpreferences;
    exports org.apache.pdfbox.printing;
    exports org.apache.pdfbox.rendering;
    exports org.apache.pdfbox.text;
    exports org.apache.pdfbox.util;
    exports org.apache.pdfbox.util.filetypedetector;
}

在 jar 的文件夹中,我运行: javac --patch-module org.apache.pdfbox=pdfbox-2.0.20.jar module-info.java

但后来我得到了

pdfbox/module-info.java:2: error: module not found: org.bouncycastle.pkix
    requires org.bouncycastle.pkix;
                             ^
pdfbox/module-info.java:3: error: module not found: org.bouncycastle.provider
    requires org.bouncycastle.provider;
                             ^
pdfbox/module-info.java:5: error: module not found: commons.logging
    requires transitive commons.logging;
                               ^
pdfbox/module-info.java:8: error: module not found: org.apache.fontbox
    requires transitive org.apache.fontbox;
                                  ^
4 errors

我怎样才能解决这个问题?有没有更好的解决方法?提前致谢。

项目:https ://github.com/ajsaraujo/mre-automodule

4

2 回答 2

1

由于自动模块问题,您不能直接使用 jlink。但是您可以按照本教程https://github.com/dlemmermann/JPackageScriptFX进行操作,该教程也使用 jlink,但仅用于创建专用运行时,而无需模块化您的项目。我也在我的项目中使用 PDFBox,所以我知道它有效。免责声明:我有偏见,因为我是上述教程的合著者:-)

于 2020-08-23T07:31:52.500 回答
0

我找到了一个关于module-info.class一步一步制作的教程。module-info.class为 org.apache.commons.math3 创建对我有用。https://www.youtube.com/watch?v=bO6f3U4i0A0&t=293

对我来说,“找不到模块”问题没有出现。

于 2021-01-05T01:51:20.810 回答