Search code examples
javajavafxbouncycastlejavafx-11jlink

How to fix "auto module name cannot be used with jlink"?


I've been working on a javafx application. Iam using Bouncy castle (for generating certificates) and google zxing library (for QR code generation). both these dependecies doesn't have a module-info.class file. When i try to run jlink it throws the following error

[INFO] 
[INFO] --- jlink:3.1.0:jlink (default-cli) @ flexi ---
[INFO]  -> module: javafx.graphicsEmpty ( C:\Users\dharu\.m2\repository\org\openjfx\javafx-graphics\11\javafx-graphics-11.jar )
[INFO]  -> module: javafx.baseEmpty ( C:\Users\dharu\.m2\repository\org\openjfx\javafx-base\11\javafx-base-11.jar )
[INFO]  -> module: org.bouncycastle.provider ( C:\Users\dharu\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.60\bcprov-jdk15on-1.60.jar )
[INFO]  -> module: com.google.zxing ( C:\Users\dharu\.m2\repository\com\google\zxing\core\3.5.0\core-3.5.0.jar )
[INFO]  -> module: javafx.base ( C:\Users\dharu\.m2\repository\org\openjfx\javafx-base\11\javafx-base-11-win.jar )
[INFO]  -> module: javafx.controls ( C:\Users\dharu\.m2\repository\org\openjfx\javafx-controls\11\javafx-controls-11-win.jar )
[INFO]  -> module: javafx.graphics ( C:\Users\dharu\.m2\repository\org\openjfx\javafx-graphics\11\javafx-graphics-11-win.jar )
[INFO]  -> module: com.github.rkdharun.flexi ( D:\Source\Flexi-desk\target\classes )
[INFO]  -> module: javafx.fxml ( C:\Users\dharu\.m2\repository\org\openjfx\javafx-fxml\11\javafx-fxml-11-win.jar )
[INFO]  -> module: javafx.fxmlEmpty ( C:\Users\dharu\.m2\repository\org\openjfx\javafx-fxml\11\javafx-fxml-11.jar )
[INFO]  -> module: javafx.media ( C:\Users\dharu\.m2\repository\org\openjfx\javafx-media\11\javafx-media-11-win.jar )
[INFO]  -> module: org.bouncycastle.pkix ( C:\Users\dharu\.m2\repository\org\bouncycastle\bcpkix-jdk15on\1.60\bcpkix-jdk15on-1.60.jar )
[ERROR] 
[ERROR] Error: automatic module cannot be used with jlink: org.bouncycastle.provider from file:///C:/Users/dharu/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.60/bcprov-jdk15on-1.60.jar

as long as i searched for this issue, it says that i should write the module-info file myself. I have no idea how to do it and Iam a newbie.

Is there a possibility to package my application with all its dependency and jre if yes please tell me how to do it.


Solution

  • As noted in comments:

    Bouncy 1.60 is over 5 years old. Any newer version -- even 1.61 -- does support modularity.

    But in general, you can't "fix" "auto module name cannot be used with jlink". jlink (as of Java 21) does not support automatic modules.

    The only solution to be able to link an automatic module, is to rebuild it as a standard module (with a module-info.java). That is what the bouncy castle library developers did for latter versions of the bouncy castle libraries.

    The other option is to not link the automatic modules into a jlink image and add them to the runtime later by placing them on the classpath or modulepath.

    Alternately, you can use jpackage as that can create packages for non-modular software, though the result is different than what jlink does.

    Tools that assist in creating module-info for non-modular software

    • ModiTect can generate module-info for dependencies that don't have it.
    • The badass jlink plugin can work with non-modular dependencies (it creates a single jar for them and adds a synthetic module info).
    • You can also unpack the jar, create and compile a module-info for it that you write yourself and add that to a repacked jar. jdeps might be able to assist you in this task.

    Detailed descriptions of how to use these tools is beyond the scope of what I am prepared to write here. I advise you to study their documentation or relevant tutorials that use them, if you would like to try them.

    None of these workarounds for non-modular dependencies is ideal nor guaranteed to work flawlessly for any non-modular software. It is best to have module-info provided from the library developers when it is available.