Error: JavaFX runtime components are missing - JavaFX 11 and OpenJDK 11 and Eclipse IDE
Your problem is not compiling the project, but running it.
Since your main
is defined in your Application
-extension, running the project will require JavaFX in your module path on startup.
So either outsource your main
into a class different from your Application
or add the JavaFX modules with VM arguments:
--module-path="<javafx-root>\lib" --add-modules="javafx.base,javafx.controls,javafx.media,…"
See this for some more info.
JavaFX runtime components are missing, even though I already have them in my VM options and Modules
Okay, so I found out why this is occurring.
I put the module path and add modules in the program arguments and not in the vm options, which is what is causing the red issue.
Now I am encountering a "Error occurred during initialization of boot layer" issue now.
IntelliJ IDEA - Error: JavaFX runtime components are missing, and are required to run this application
There are similar questions like this or this other one.
Before JavaFX 11, whenever you were calling something JavaFX related, you had all the javafx modules available within the SDK.
But now you have to include the modules/dependencies you need.
Your error says that you are using FXML but it can't be resolved, but you have just added the javafx.controls
module:
--add-modules=javafx.controls
As you can see in the JavaDoc the javafx.controls
module depends on javafx.graphics
and java.base
, but none of those modules includes the FXML classes.
If you need FXML classes like the FXMLLoader
, you need to include javafx.fxml
module:
--module-path="C:\Program Files\Java\javafx-sdk-11\lib" \
--add-modules=javafx.controls,javafx.fxml
The same will apply if you need media or webkit, those have their own modules.
Error: JavaFX runtime components are missing, (Permanent Solution)
Recommended Alternatives
See the packaging resources of the JavaFX tag for recommended alternate solutions to a jar distribution: jlink, jpackage, or native image.
Using JRE's that include JavaFX
Pre-installed JREs that include JavaFX, such as some Bellsoft, Zulu, and Corretto distributions, will execute JavaFX apps without additional module specifiers because they include the JavaFX modules in the base module setup for their distributions.
Note, you must use the correct versions of the JDKs if you want a JDK which includes JavaFX (not all JDKs include JavaFX):
- for BellSoft, download and install the "Full JDK", not the "Standard JDK".
- for Zulu, download and install the package type "JDK FX", not "JDK".
You can also create your own JRE distribution that includes JavaFX modules using jlink (which is actually simpler to do than it may sound).
Using ant to build a single JAR containing App and JavaFX components
But I still hope that there might be a solution for the above while working with ANT as building tool for JavaFX.
There is some info on building modular JavaFX apps with ant in this answer:
- bad name in value for --add-modules when trying to compile through ant
It probably isn’t everything you are looking for though.
To create a single executable jar using ant, you could try emulating the output of this maven JavaFX shade on classpath answer:
- Maven Shade JavaFX runtime components are missing
But use ant tasks to build the massive shaded jar instead of maven. I don’t have explicit instructions for that, you would need to work out to accomplish that non-trivial task yourself.
The created jar will include a launcher class, your application code, dependent library code, JavaFX java, and native code. The jar will run on any modern JRE as long as you have included the native code for the relevant platform. The jar will run in the unsupported classpath configuration.
Zip Distributions
Or (better) create a zip distribution:
only put your own code in your app jar.
place the dependent libraries and JavaFX modules in a lib directory.
Create a script that invokes Java with your jar file running with the modules in the lib directory added.
Make your app modular if possible:
- Define a
module-info.java
. - This step isn’t strictly necessary or reasonably possible for some apps.
- Define a
Use ant to place everything in a zip file for distribution.
Include a jlink generated JRE in the zip if you want.
Note: the maven JavaFX plugin, once properly configured, can accomplish most of these tasks with a single command:
mvn javafx:jlink
Additional info
- See the eden guide for resolving JavaFX runtime components.
JavaFX 11: JavaFX runtime components are missing
As a first time user, I've managed to make it work, but it was not straightforward to me.
I guess there are no many people familiarized with this IDE, so I'm going to post the steps I followed, as a basic tutorial:
Download and install jGRASP version 2.0.5_05 Beta.
Since I have a few JDKs installed, it selected by default JDK 10.0.2, so my first step was to find a way to work with JDK 11. That can be done in
Settings -> jGrasp Startup Settings
, where I can set the path for myjava
executable:
Then I restarted jGrasp. You can verify which JDK the IDE is using in Tools -> System Info -> Java Version
.
Open HelloFX sample class. I've started with the most basic sample from the OpenJFX docs. The code can be found here.
Build -> compile
, as expected, will throw a bunch of errors given that JavaFX is no longer part of the JDK:
Following the OpenJFX docs, we need to download the JavaFX SDK from here, and then add the library to the classpath. Go to
Settings -> PATH/CLASSPATH -> Workspace
, press New, and add, one by one, the different JavaFX jars from the downloaded SDK/lib folder (at leastjavafx-base.jar
,javafx-graphics.jar
andjavafx-controls.jar
).Build -> compile
should work now.Next step:
Build -> Run
. This fails:
----jGRASP exec: java HelloFX
Error: JavaFX runtime components are missing, and are required to run this application
----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.
That was expected. According to the docs, we need to set the module-path and add-modules arguments.
- First attempt: use
Run arguments
. After setting:
--module-path /Users/<user>/Downloads/javafx-sdk-11.0.2/lib --add-modules javafx.controls
running again failed with the exact same error message as above, but with one difference in the console log:
----jGRASP exec: java HelloFX --module-path /Users/<user>/Downloads/javafx-sdk-11.0.2/lib --add-modules javafx.controls
What's wrong with that!? Well... if you try that on command line, it will fail as well, because the order of arguments is wrong, the vm arguments should go before the class name.
In conclusion: Run arguments
are not VM arguments
!
- Second attempt: In order to provide the VM arguments, the option I found was to edit
Settings -> Compiler settings -> Workspace
. By default, it is usingjdk (integrated debugger) - generic
. You can view it and see that forRun
it uses:
java %S -ea %S %<FLAGS2> %<MAIN_CLASS> %<ARGS>
So instead of ARGS
we need to find a way to set FLAGS2
.
Luckily, next to the Environment
tab, there is a Flags/Args
tab, and there we can set our vm arguments in FLAGS2
:
--module-path /Users/<user>/Downloads/javafx-sdk-11.0.2/lib --add-modules javafx.controls
- Apply, close the dialog, and
Build -> Run
the class, now it will work!
If you see the console log, it contains exactly the command you would use when running on command line:
----jGRASP exec: java --module-path /Users/<user>/Downloads/javafx-sdk-11.0.2/lib --add-modules javafx.controls HelloFX
----jGRASP: operation complete.
I guess the next step will be running a more complex project...
Related Topics
Managing Constructors with Many Parameters in Java
Mockito: Trying to Spy on Method Is Calling the Original Method
Why Do We Assign a Parent Reference to the Child Object in Java
Maven: Failed to Read Artifact Descriptor
Functional Style of Java 8's Optional.Ifpresent and If-Not-Present
Get Maven Artifact Version at Runtime
Java Recursive Fibonacci Sequence
Where Is the Documentation for the Values() Method of Enum
Converting Secret Key into a String and Vice Versa
Named Placeholders in String Formatting
Java Synchronized Block for .Class
Get an Outputstream into a String
How to Determine If a Number Is a Prime with Regex
Retrieving a List from a Java.Util.Stream.Stream in Java 8
How to Get the Filename Without the Extension in Java
In Log4J, Does Checking Isdebugenabled Before Logging Improve Performance