0

I have a (non-modular) JavaFX application that runs well from the command line, as I give to the command line the arguments --module-path and --add-modules to include the javafx modules (in my case, I use

--module-path /home/user/libs/javafx_libs --add-modules javafx.controls,javafx.fxml,javafx.web

This works fine, because I know where I had manually installed my javafx files (i.e. in /home/user/libs/javafx_libs).

However, I now want to build it, but

  1. not using some manual extraction directory location, but using maven dependencies, and
  2. in one single application jarfile without any platform-specific dependencies.

So my maven dependencies look like :

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>${version.javafx}</version>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>${version.javafx}</version>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-web</artifactId>
    <version>${version.javafx}</version>
</dependency>

As far as I understand, I have to make my complete application modular, which is (another) new thing to me, but the first basic steps have been completed (added a module-info.java file, and added it's "requires"- statements). I want to build this application so that I can start it without these module paths and module additions.

My questions are:

  1. Where can I then find the location of Maven's repository's JavaFX files,
  2. How can I build this in one single jar file, and
  3. How is such a build done in Maven? That is, which plugins do I need to build it this way, and how do I configure these plugins in Maven?

I may also be helped by getting a link to some good book (or to some other publication) where this is explained.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
sudo
  • 188
  • 10
  • Matteo, thank you for your quick response. However, I can already build the fat jar, but not including the modules. My maven setup can already now generate the (non-modular) fat jar, but not the jar including the javafx modules... – sudo Jul 04 '22 at 13:16
  • 1
    Fat jars for JavaFX are not well supported. Read the chapter on Packaging here: https://stackoverflow.com/tags/javafx/info – mipa Jul 04 '22 at 13:30
  • I read your link, and more specifically the link in it : https://stackoverflow.com/questions/52653836/maven-shade-javafx-runtime-components-are-missing Now I already encapsulate the JavaFX main class in some other main class (that itself doesn't extend JavaFX's Application). I don't want to cross-compile for another platform either. I think there should be possibilities with jlink and jpackage, but I'd like to know how to use these. Besides that, I think building a non-modular app with any other module besides JavaFX would have to be generated in a comparable way... ? – sudo Jul 04 '22 at 13:37
  • Noteworthy : running "mvn clean javafx:jlink" produces the error Required filename-based automodules detected. Please don't publish this project to a public artifact repository! Error: automatic module cannot be used with jlink: – sudo Jul 04 '22 at 13:56
  • 2
    For a non-modular setup you might want to read this: https://github.com/dlemmermann/JPackageScriptFX – mipa Jul 04 '22 at 15:28
  • @mipa : thank you, I'm reading this, and I'll try to carefully understand what is said there, and how this all works together. One question immediately pops into my limited-modular-build-knowledgeable brain, however, especially as you mention it can be used specifically with non-modular projects : won't I receive the jlink error I mentioned above, for my automatic modules (unless, of course, jlink's script-provided arguments are taking care of that error) ? Maybe too early to ask this before trying this out in detail ... – sudo Jul 04 '22 at 18:37
  • 2
    The `jlink` tool can only work with _non-automatic_ modules (i.e., those modules which have an explicit `module-info` descriptor). But if you combine this with `jpackage`, then you can still work with non-modular applications. Use `jlink` to build a custom run-time image containing all non-automatic modules (including JavaFX), and then have `jpackage` place everything else on the class-path. Note you don't necessarily have to invoke `jlink` and `jpackage` separately; the latter will use the former behind the scenes if needed. – Slaw Jul 05 '22 at 03:28
  • 1
    Note applications packaged with `jlink` (+ `jpackage`) are platform-dependent. For JavaFX applications, the `jlink` tool [works best with the JMOD files](https://stackoverflow.com/questions/61294243/running-javafx-application-after-jpackage/61294909#61294909), which you can only get from Gluon, though it will work with the Maven Central JAR files. If you truly want a platform-independent executable JAR file, without including any native code from JavaFX, then you would need to do something like require your users to have a Java run-time installed that includes JavaFX. – Slaw Jul 05 '22 at 03:39

0 Answers0