launching JavaFX in 11
johan.vos at gluonhq.com
Tue Jun 5 13:40:09 UTC 2018
I'm a bit confused on the different options for launching JavaFX
applications with the latest Java 11 code.
When running an app from maven, it worked fine. Maven uses the classpath
and not the module path, so I assumed that running the same app using
java -cp all-javafx-jars Main
would work too. But it doesn't. The error I got is this:
Error: JavaFX runtime components are missing, and are required to run this
This error comes from sun.launcher.LauncherHelper in the java.base module.
The reason for this is that the Main app extends Application and has a main
method. If that is the case, the LauncherHelper will check for the
javafx.graphics module to be present as a named module:
Optional<Module> om =
If that module is not present, the launch is aborted.
Hence, having the JavaFX libraries as jars on the classpath is not allowed
in this case.
Fair, but that doesn't explain why it works via maven. The reason is that
maven doesn't start a new VM process, hence the main class is in this
case org.codehaus.plexus.classworlds.launcher.Launcher which does not
extend Application, hence it doesn't do the check on javafx.graphics module
to be present as a named module, and when the required jars (including
native code) are on the classpath, it works fine.
I thought the check on the main class extending
javafx.application.Application was removed from the core JDK, but it is
still there, so I understand why it works using maven and fails using a
standalone java invocation.
While I fully agree the goal is to have the JavaFX modules as named modules
on the module path, I think this will create confusion. A simple workaround
is to have a separate main class that doesn't extend Application, but that
seems a real dirty solution.
But maybe I'm missing something?
More information about the openjfx-dev