'Add JavaFX jmods to java --list-modules

Preface:

I need to open .jar files which requires Java and JavaFX. I have installed both Java (from Oracle website) and JavaFX (SDK from openjfx website). I have added environment variables by updating /etc/environment file, and adding JAVAFX_HOME="path/to/JavaFX".

/etc/environment file looks like:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk-12.0.2/bin"
JAVA_HOME="/usr/lib/jvm/jdk-12.0.2"
JAVAFX_HOME="/home/joshi/Documents/javafx-sdk-12.0.2/lib"

For now, I can get a .jar file running by executing:

java --module-path $JAVAFX_HOME --add-modules ALL-MODULE-PATH -jar myfile.jar

There are multiple .jar files, which makes executing above command pretty troublesome. Name of .jar files are pretty non-catchy and complex too.

Question:

I want to know if I can add JavaFX jmods to Java permanently. For example, when we execute in terminal java --list-modules, it should include JavaFX mods in it too.

I have tried:

  1. Copying JavaFX jmod files in /usr/lib/jvm/jdk-12.0.2/jmods. But even after rebooting, java --list-modules doesn't include JavaFX mods. I have also ran
    sudo update-alternatives --config java 
    sudo update-alternatives --config javac
  1. I don't think creating .sh script files would be a great idea as there would need to be as many script files as there are .jar files.

Any help is highly appreciated. I am on Kubuntu.



Solution 1:[1]

You can use environment variable: _JAVA_OPTIONS. All options specified in this variable will be appended to the JVM startup args.

export _JAVA_OPTIONS="--module-path=/path/to/JavaFX --add-modules=ALL-MODULE-PATH"

Solution 2:[2]

Do not download and install the SDK zip file. Instead download and install the jmods zip file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Eric Espino