4

I’m having some issues including Controlsfx when using Jpackage.

I have set up a project in IntelliJ with JavaFX using a Archetype from Maven Central. Works fine with JavaFX in IntelliJ. I can package it with Maven (from IntelliJ) and use JPackage for making an exe-installer, that also works fine. I’m using this command with JPackage:

jpackage --input C:\...\target --add-modules javafx.controls --module-path C:\...\openjfx-20.0.1_windows-x64_bin-jmods\javafx-jmods-20.0.1 --module-path --win-console --dest c:\outputs --main-jar tests-1.0-SNAPSHOT.jar --main-class tests.App

Now I want to incorporate ControlsFX so I download the ControlsFX .JAR from Maven: https://mvnrepository.com/artifact/org.controlsfx/controlsfx/11.1.2IntelliJ In IntelliJ I add it as a Module. All fine, I wan use ControlsFX in my project.

Now I want to make an exe-installer (like above without ControlsFX) so I add ControlsFX to my JPackage command:

jpackage --input C:\...\target --add-modules javafx.controls,controlsfx --module-path C:\...\openjfx-20.0.1_windows-x64_bin-jmods\javafx-jmods-20.0.1 --module-path C:\..\controlsfx --win-console --dest c:\test --main-jar tests-1.0-SNAPSHOT.jar --main-class tests.App

When running the command I get this:

java.lang.module.FindException: Module controlsfx not found

I know my issue is related to the command I pass to JPackage but cant figure out what is.

droid
  • 103
  • 1
  • 15

1 Answers1

5

As mentioned by @Slaw in comments below, you have used the wrong module name. You can confirm the module name of a jar by viewing the module definition. This tells you the name of the module to use with jpackage eg org.controlsfx.controls or will print No module descriptor found. Derived automatic module. if a non module jar:

jar --file=controlsfx.jar --describe-module
org.controlsfx.controls@11.1.2 jar:file:///c:/dev/mods/controlsfx.jar!/module-info.class
... plus details of exports

The jpackage command will use jlink internally to build a runtime image that contains all the modules listed:

jpackage --input myinput --add-modules javafx.controls,org.controlsfx.controls --module-path c:\xyz...\javafx-jmods-NN --module-path c:\abc...\controlsfx.jar  --dest myoutput {otherargs}

After installation you can check which modules are in the installed runtime with:

 C:\Program Files\XYZ\runtime\bin\java --list-modules
 ...
 javafx.controls@somever
 ...
 org.controlsfx.controls@somever

Alternatively you can use a jar (module or non module) with jpackage by copying the jar into your target release structure somewhere under the --input directory. Then it will be picked up as a classpath jar dependency (inside the release directories) rather than as a module dependency (inside the runtime image as above).

You can check if a jar was added as as classpath dependency by looking at the generated {launcher}.cfg, it should contain a line:

 app.classpath=$APPDIR\whateverplaceunder--input.dir\controlsfx.jar
DuncG
  • 12,137
  • 2
  • 21
  • 33
  • Hi. That makes sense. I don't have the controlsfx.jmod, not sure it exists. I will try what you recommend when only having the .rar. Can you please add a little bit more information about the dependency part, not completely sure where to start :) I read that I don't have to pass any information about Controlsfx to JPackage? – droid May 20 '23 at 14:23
  • 1
    Edit: Its working now, using what you recommended. Thank you very much. – droid May 20 '23 at 14:29
  • 2
    `jlink` does not require JMOD files. As long as the JAR file has a `module-info` descriptor it will work just fine. You only need a JMOD file if you want to package things like native code and licenses along with your class files in a clean manner. – Slaw May 20 '23 at 22:14
  • 2
    @droid You have `--add-modules javafx.controls,controlsfx` in your question, but the [module name](https://github.com/controlsfx/controlsfx/blob/0a8caa4ad2abb3dea48fecb10819ea540748e308/controlsfx/src/main/java/module-info.java#L31) for _ControlsFX_ is `org.controlsfx.controls`. – Slaw May 20 '23 at 22:18
  • @Slaw that is useful info about jmod files, I shall amend my answer. – DuncG May 21 '23 at 07:42
  • I just tried again with the correct package name and this time JPackage runs fine and the installed program also works fine. Thanks. I learned a lot. – droid May 21 '23 at 15:17
  • @droid Sorry to be pedantic, but you used the wrong **module** name, not the wrong _package_ name. Regardless, I'm glad you got it to work :) – Slaw May 22 '23 at 06:40