1

Backstory: I'm trying to distribute my openJDK11,openJFX application to my friend. I'm using this tutorial: https://medium.com/azulsystems/using-jlink-to-build-java-runtimes-for-non-modular-applications-9568c5e70ef4

You can see here that javafx is listed in my dependencies:

IntelliJ dependencies view

You can see here that my module-info is set up as might be required to run the application:

module FractalFriend_m {


    requires javafx.base;
    requires javafx.controls;
    requires javafx.fxml;
    requires javafx.graphics;

    opens com.potatospy;


}

You can see here that my VM Options are entered correctly:

--module-path=C:\Users\USERNAME\Documents\javafx-sdk-11.0.2\lib --add-modules=javafx.controls,javafx.fxml,javafx.base,javafx.graphics

Running:

jdeps --module-path C:\Users\USERNAME\Documents\javafx-sdk-11.0.2\lib --list-deps FractalFriend_m.jar

Results in:

 java.base
   javafx.base
   javafx.controls
   javafx.fxml
   javafx.graphics

And finally, I run jlink to hopefully produce something anyone can run:

jlink --no-header-files --no-man-pages --compress=2 --strip-debug --add-modules javafx.controls,javafx.fxml,javafx.base,javafx.graphics --output java-runtime

Which results in:

Error: Module javafx.base not found

chrips
  • 4,996
  • 5
  • 24
  • 48
  • The option should be `--output` (two dashes). – Slaw Feb 20 '19 at 01:20
  • @Slaw THanks very much. I'm updating with my results. "Error: Module javafx.base not found" – chrips Feb 20 '19 at 01:24
  • You don't specify the module path (`-p` or `--module-path`). Note, for `jlink` you should be pointing to the JMOD files, as they contain the native code. – Slaw Feb 20 '19 at 01:26
  • @Slaw Lord I Dont even know what JMOD is *cries* – chrips Feb 20 '19 at 01:28
  • They're basically JAR files but can package native code (along with other stuff). In my experience so far, they're really only used with `jlink` (see [this question](https://stackoverflow.com/questions/44732915/why-did-java-9-introduce-the-jmod-file-format)). Since some JavaFX modules require native code you should use the JMOD files which you can get from [here](https://gluonhq.com/products/javafx/)—same place you (probably) got the SDK from. – Slaw Feb 20 '19 at 01:37
  • "_And finally, I run jlink to hopefully produce something anyone can run_". Note that `jlink` results in a platform-specific image. For instance, an image built for Windows won't run on Linux or Mac. This is not unexpected as the JDK itself is platform-specific (and so is the JavaFX SDK). However, it is possible to create images for other platforms—see https://stackoverflow.com/questions/47593409/create-java-runtime-image-on-one-platform-for-another-using-jlink/47594270. You'd have to download the target JDK and the appropriate JavaFX JMODs. – Slaw Feb 20 '19 at 01:42
  • @Slaw OK thanks. I'll head down that road now! Yeah I want to produce runnables for mac as well. Probably linux too if I can do it efficiently. – chrips Feb 20 '19 at 01:52
  • 2
    The [OpenJFX docs](https://openjfx.io/openjfx-docs/#IDE-Intellij) contain several use cases to create a custom runtime with `jlink`. If you use Gradle there is a very convenient [plugin](https://github.com/beryx/badass-jlink-plugin) as well. – José Pereda Feb 20 '19 at 09:57

1 Answers1

0

JavaFX should be downloaded separately and on calling jlink it should be specified with the -p (--module-path) argument.

jlink --no-header-files --no-man-pages --compress=2 --strip-debug -p <path_java_fx_sdk_lib> --add-modules javafx.controls,javafx.fxml,javafx.base,javafx.graphics  --output java-runtime

jtkSource
  • 675
  • 9
  • 21