IntelliJ IDEA 2018.2、openjdk 11 和 openjfx 11(没有 maven,不是模块化项目):找不到模块 javafx.controls
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52889537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IntelliJ IDEA 2018.2, openjdk 11 and openjfx 11 (no maven, not modular project) : Module javafx.controls not found
提问by Gilles
I just created a new JavaFX project in intelliJ with an openjdk 11 and I've downloaded the last openjfx library on their website.
我刚刚使用 openjdk 11 在 intelliJ 中创建了一个新的 JavaFX 项目,并且我已经在他们的网站上下载了最后一个 openjfx 库。
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
我已添加到运行/调试 VM 选项:--module-path %PATH_TO_FX% --add-modules=javafx.controls,javafx.fxml
VM 选项
I've added a new variable env PATH_TO_FX : PATH_TO_FX=%programfiles%\Java\javafx-sdk-11\lib
我添加了一个新变量 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
PS:我已经按照这个链接https://openjfx.io/openjfx-docs/#install-javafx
EDIT :
编辑 :
Should I have onpenjfx libraries here ? classpath
我应该在这里有 onpenjfx 库吗?类路径
回答by liuyez123
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.
显示此错误是因为 Java 11 启动器会检查主类是否扩展了 javafx.application.Application。如果是这种情况,则需要在模块路径上有 javafx.graphics 模块。
- Add VM options
- 添加虚拟机选项
To solve the issue, click on Run -> Edit Configurations... and add these VM options:
要解决此问题,请单击“运行”->“编辑配置...”并添加以下 VM 选项:
--module-path %PATH_TO_FX% --add-modules=javafx.controls,javafx.fxml
--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.
请注意,IntelliJ 创建的默认项目使用 FXML,因此需要 javafx.fxml 和 javafx.controls。如果您的项目使用其他模块,您也需要添加它们。
Click apply and close the dialog.
单击应用并关闭对话框。
- Run the project
- 运行项目
Click Run -> Run... to run the project, now it should work fine.
单击 Run -> Run... 运行项目,现在它应该可以正常工作了。
回答by liuyez123
To solve the issue, click on Run -> Edit Configurations... and add modify the path variable as follows:
要解决此问题,请单击 Run -> Edit Configurations... 并添加修改路径变量,如下所示:
--module-path ${PATH_TO_FX} --add-modules=javafx.controls,javafx.fxml