Using JavaFX with Intellij IDEA

旧街凉风 提交于 2019-12-04 06:02:11

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 the issue is quite clear: 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:

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!