IntelliJ IDEA 2018.2, openjdk 11 and openjfx 11 (no maven, not modular project) : Module javafx.controls not found

Gilles picture Gilles · Oct 19, 2018 · Viewed 16.6k times · Source

I just created a new JavaFX project in intelliJ with an openjdk 11 and I've downloaded the last openjfx library on their website.

Here is what I did :

I've added to Run/Debug VM options : --module-path %PATH_TO_FX% --add-modules=javafx.controls,javafx.fxml VM Options

I've added a new variable env PATH_TO_FX : PATH_TO_FX=%programfiles%\Java\javafx-sdk-11\lib

So it compiles good but it fails at runtime :

Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found

Does anyone know what am I missing here ?

PS : I've followed this link https://openjfx.io/openjfx-docs/#install-javafx

EDIT :

Should I have onpenjfx libraries here ? classpath

Answer

liuyez123 picture liuyez123 · Nov 20, 2018

This error is shown since the Java 11 launcher checks if the main class extends javafx.application.Application. If that is the case, it is required to have the javafx.graphics module on the module-path.

  1. Add VM options

To solve the issue, click on Run -> Edit Configurations... and add these VM options:

--module-path %PATH_TO_FX% --add-modules=javafx.controls,javafx.fxml

Note that the default project created by IntelliJ uses FXML, so javafx.fxml is required along with javafx.controls. If your project uses other modules, you will need to add them as well. enter image description here

Click apply and close the dialog.

  1. Run the project

Click Run -> Run... to run the project, now it should work fine.