0

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

Allan Juan
  • 2,048
  • 1
  • 18
  • 42
  • (***Q1***). Do you have a git repository with your project in it that you could share? (***Q2***). Your _`module-info.java`_ declares a module named _`org.apache.pdfbox`_. Your _`--patch-module`_ command is given a module named _`pdfbox`_. Is that intentional? (***Q3***). If that's intentional, then can you help me understand why, please? (***Q4***). What version of the JDK and JavaFX are you using? TIA. – deduper Aug 23 '20 at 00:45
  • 1. I can't share the actual code since it's closed source, but I came up with an MRE, I edited the post with a link to it. 2-3. Yeah you're right, it was not on purpose. However when I do it the right way I still get the same error. My coworker managed to generate a `module-info.class` file but I don't know what to do with it either. 4. I'm using JavaFX13 and OpenJDK 14. Thanks! :) – Allan Juan Aug 23 '20 at 12:50
  • Did you find any solution @AllanJuan since then? I've got the same problem with PDFBox on trying to use jlink. – Drimux Oct 21 '22 at 12:59

2 Answers2

1

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 :-)

mipa
  • 10,369
  • 2
  • 16
  • 35
0

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.

Eni
  • 11
  • 1