I am just made aware that there is this new thing called a module in Java from Java9, and that JavaFX is isolated/unbundled from Java11, so JavaFX needs to be separately downloaded from OpenJFX. I have no idea what's the difference between the SDK and jmods (Java modules) downloads, and no I am a beginner and not using any Maven/Gradle builds.
To compile a file.java having some module imports, it seems I must explicitly provide the module path (instead of setting a fixed path like classpath)
I would prefer using the JavaFX module just like a good-old package and to have a classpath automatically locate the imported classes. In Windows, I do
But I still have to do a long and error-prone
So I decided to instead shorten the pain
Up to this point, fine although I still don't understand Java modules. But I don't understand why I also need to provide %JAVAFX% to run the compiled file.
This suggests that JavaFX isn't included in JRE. So we need to have both JRE and JavaFX runtime to use Java applications? How are users expected to have JavaFX runtime on top of JRE? Or is it the developer's job to include JavaFX runtime into a jar, so anyone can open and have JavaFX working? That is, how to just have JVM run any classes (having javafx or not)?
To compile a file.java having some module imports, it seems I must explicitly provide the module path (instead of setting a fixed path like classpath)
Code:
javac --module-path THE_PATH_TO_JAVAFX_LIB --add-modules javafx.controls the_file.java
I would prefer using the JavaFX module just like a good-old package and to have a classpath automatically locate the imported classes. In Windows, I do
Code:
set JAVAFX="Program Files\path\javafx-sdk-11.0.1\lib"
But I still have to do a long and error-prone
Code:
javac --module-path %JAVAFX% --add-modules javafx.controls the_file.java
So I decided to instead shorten the pain
Code:
set JAVAFX=--module-path "Program Files\path\javafx-sdk-11.0.1\lib" --add-modules javafx.controls
javac %JAVAFX% the_file.java
Up to this point, fine although I still don't understand Java modules. But I don't understand why I also need to provide %JAVAFX% to run the compiled file.
Code:
java the_file //java.lang.NoClassDefFoundError
java %JAVAFX% the_file //this is fine
This suggests that JavaFX isn't included in JRE. So we need to have both JRE and JavaFX runtime to use Java applications? How are users expected to have JavaFX runtime on top of JRE? Or is it the developer's job to include JavaFX runtime into a jar, so anyone can open and have JavaFX working? That is, how to just have JVM run any classes (having javafx or not)?
Last edited: