javajavafxjgraspjavafx-11

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.


Solution

  • 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:

    SetJDK 11

    Then I restarted jGrasp. You can verify which JDK the IDE is using in Tools -> System Info -> Java Version.

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

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

    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

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