模块未在尝试注入 module-info.java 时找到。

huangapple go评论66阅读模式
英文:

Modules not found when trying to inject module-info.java

问题

我有一个使用Apache的PDFBox的JavaFX项目。我想使用JLink来构建它的JRE,但是由于PDFBox是一个自动模块,所以我不能这样做。因此,我正在尝试在其中注入一个module-info文件。

我使用jdeps生成了这个module-info文件:

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 ...
}

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

但是我得到了以下错误:

pdfbox/module-info.java:2: 错误: 找不到模块: org.bouncycastle.pkix
    requires org.bouncycastle.pkix;
                             ^
pdfbox/module-info.java:3: 错误: 找不到模块: org.bouncycastle.provider
    requires org.bouncycastle.provider;
                             ^
pdfbox/module-info.java:5: 错误: 找不到模块: commons.logging
    requires transitive commons.logging;
                               ^
pdfbox/module-info.java:8: 错误: 找不到模块: org.apache.fontbox
    requires transitive org.apache.fontbox;
                                  ^
4 个错误

我该如何解决这个问题?还有更好的解决方法吗?提前谢谢。

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

英文:

I have a JavaFX project that uses Apache's PDFBox. I want to use JLink to build a JRE of it, but I can't since PDFBox is an automodule. Thus, I'm trying to inject a module-info file in it.

I generated this module-info file using 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;
}

At the jar's folder, I ran:
javac --patch-module org.apache.pdfbox=pdfbox-2.0.20.jar module-info.java

But then I got

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

How can I fix this? Is there any better workaround? Thanks in advance.

The project: https://github.com/ajsaraujo/mre-automodule

答案1

得分: 1

因为自动模块的问题,您不能直接使用 jlink。但是您可以按照这个教程 https://github.com/dlemmermann/JPackageScriptFX 进行操作,该教程也使用了 jlink,但仅用于创建一个专用运行时,而无需将项目模块化。我在我的项目中也在使用 PDFBox,所以我知道它是可行的。免责声明:由于我是上述教程的共同作者,所以我持有偏见 模块未在尝试注入 module-info.java 时找到。

英文:

You cannot use jlink directly because of the automatic module issue. But you can follow this tutorial https://github.com/dlemmermann/JPackageScriptFX which also uses jlink but only to create a dedicated runtime without having to modularize your project. I am also using PDFBox in my project, so I know it works. Disclaimer: I am biased because I am the co-author of the above mentioned tutorial 模块未在尝试注入 module-info.java 时找到。

答案2

得分: 0

我找到了一个关于逐步制作 module-info.class 的教程。
对我而言,这个教程有效,成功为 org.apache.commons.math3 创建了 module-info.class
<https://www.youtube.com/watch?v=bO6f3U4i0A0&t=293>

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

英文:

I found a tutorial about making the module-info.class step by step.
It worked for me to create module-info.class for org.apache.commons.math3 .
<https://www.youtube.com/watch?v=bO6f3U4i0A0&t=293>

For me, the 'module not found' issue didn't show up.

huangapple
  • 本文由 发表于 2020年8月23日 05:20:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/63541209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定