Using JavaFX with Intellij IDEA
Based on the posted command line, this is what IntelliJ applies to run your project:
"C:\Program Files\Java\jdk-11.0.1\bin\java.exe" --module-path %PATH_TO_FX% --add-modules=javafx.controls,javafx.fxml
So in the VM options you have set verbatim what the tutorial says:
But you haven't applied your real path for PATH_TO_FX
, as it is suggested in the picture inserted after that command in the tutorial:
IntelliJ doesn't resolve that variable and the module path is not set, hence you get the expected error that reveals that the JavaFX modules are not found:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found
Solution
This can be solved in two ways:
- Apply your path:
Edit run configurations, and in the VM options add your path:
--module-path "C:\Program Files\Java\javafx-sdk-11.0.1\lib" --add-modules=javafx.controls,javafx.fxml
Apply, and run. It should work.
- Add the environment variable
You can also set an environment variable. Go to IntelliJ->File->Settings->Appearance & Behavior->Path Variables
, and add PATH_TO_FX
, with the path to the lib
folder:
And then you can use the literals $PATH_TO_FX$
(Does not work for IntelliJ IDEA 2021.1 (Community Edition) on Windows) or ${PATH_TO_FX}
in the VM options:
--module-path ${PATH_TO_FX} --add-modules=javafx.controls,javafx.fxml
Apply, and run.
Note that this is a more permanent solution that can be apply to any other JavaFX project.