1

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.

Omid
  • 5,823
  • 4
  • 41
  • 50
Sanmay Joshi
  • 115
  • 1
  • 2
  • 9
  • Have a look at this https://openjfx.io/openjfx-docs/#modular (section: Custom JDK+JavaFX image). The idea is to create your custom JDK with JavaFX included. – José Pereda Aug 12 '19 at 10:36

2 Answers2

3

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"

northpl93
  • 524
  • 4
  • 8
  • 1
    Setting `_JAVA_OPTIONS="--module-path /path/to/JavaFX --add-modules ALL-MODULE-PATH"` threw following error: `Picked up _JAVA_OPTIONS: --module-path /home/sanmay/Documents/javafx-sdk-12.0.2/lib --add-modules ALL-MODULE-PATH Unrecognized option: --module-path Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.` – Sanmay Joshi Aug 12 '19 at 11:12
  • Does it work when you use `=` instead of spaces? For example: `--module-path=/path/to/JavaFX --add-modules=ALL-MODULE-PATH` – northpl93 Aug 12 '19 at 11:29
  • I got also Error: Could not create the Java Virtual Machine but then I added quotemarks around java fx path: "--module-path=/path/to/JavaFX" and it worked (Windows) – Tomislav Brabec Feb 08 '21 at 20:19
0

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

  • would you elaborate on how one does this? jmod files do not appear to be implicitly recognized in the same way. `Error occurred during initialization of boot layer java.lang.module.FindException: Module javafx.controls not found` – Jody Sowald Feb 15 '23 at 20:35