Error: Javafx Runtime Components Are Missing, and Are Required to Run This Application with Jdk 11

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:

  1. only put your own code in your app jar.

  2. place the dependent libraries and JavaFX modules in a lib directory.

  3. Create a script that invokes Java with your jar file running with the modules in the lib directory added.

  4. Make your app modular if possible:

    • Define a module-info.java.
    • This step isn’t strictly necessary or reasonably possible for some apps.
  5. Use ant to place everything in a zip file for distribution.

  6. 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 my java executable:

SetJDK 11

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:

Compile fails

  • 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 least javafx-base.jar, javafx-graphics.jar and javafx-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 using jdk (integrated debugger) - generic. You can view it and see that for Run 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

VM args

  • 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



Leave a reply



Submit