Jim Huggins
Jim Huggins

Reputation: 45

JavaFX 11: "JavaFX runtime components are missing"

I'm trying to run sample JavaFX code (taken from the 5th edition of Java Illuminated) under JavaFX 11 and Java 11, using jGRASP 2 under Windows 10.

I've read through the "Getting Started with JavaFX" guide (https://openjfx.io/openjfx-docs/) extensively, and while I've made some progress, I'm stuck.

I've downloaded the latest ZIP file, unpacked it, and updated the CLASSPATH to include a path to the jar files needed to compile. I can successfully compile the file. However, when I try to run, I get the following error message:

Error: JavaFX runtime components are missing, and are required to run this application

The "Getting Started" guide says that this can be fixed by adding the following options to the runtime call:

--module-path "[path]\lib" --add-modules=javafx.controls,javafx.fxml

I've added the options, but I'm still getting the error message.

Previous StackOverflow articles usually end with the option setting above; alas, I can't figure out what else to do.

Upvotes: 3

Views: 4778

Answers (2)

Dave The Dane
Dave The Dane

Reputation: 889

Try simply creating a launcher with only a main Method. It could look something like this:

package application;

import javafx.application.Application;

public class MyAppLauncher {

    public static void main(final String[] args) {
        Application.launch(MyApp.class, args);
    }
}

(you can leave the old main Method unused in your App for the time-being)
This worked for me with JDK 13 & JavaFX 13 & Eclipse 2019-12 under Ubuntu.
(I created the Project using "new/Maven Project/Simple Project" and then just added JavaFX, Logging & other stuff as dependencies in pom.xml, which all landed on the Classpath. Only the JDK was on the Modulepath)
No need to bother about Java Modules.

If that works, you can take time to learn about Java Modularisation another day...
...and remember to vote for this Answer. :-)

Upvotes: 1

José Pereda
José Pereda

Reputation: 45486

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...

Upvotes: 4

Related Questions