未找到模块:javafx.controls
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54055598/
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
Module not found: javafx.controls
提问by Oksana Oryekhovska
I have downloaded JavaFX SDK, unpacked it and set a PATH_TO_FX
system variable, following this instructions. I used following code example:
我已经下载了 JavaFX SDK,将其解压缩并PATH_TO_FX
按照此说明设置了系统变量。我使用了以下代码示例:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloFX extends Application {
@Override
public void start(Stage stage) {
String javaVersion = System.getProperty("java.version");
String javafxVersion = System.getProperty("javafx.version");
Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
Scene scene = new Scene(new StackPane(l), 640, 480);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Tried to compile it with the suggested pattern:
尝试使用建议的模式编译它:
javac --module-path $PATH_TO_FX --add-modules javafx.controls HelloFX.java
javac --module-path $PATH_TO_FX --add-modules javafx.controls HelloFX.java
But compiler throws an error: module not found: javafx.controls. Windows 10. Java and JavaFX versions is 11.0.1
但是编译器抛出一个错误:找不到模块:javafx.controls。Windows 10。Java 和 JavaFX 版本是 11.0.1
Again: I DID ADD the line --add-modules javafx.controls
再次:我确实添加了--add-modules javafx.controls 行
采纳答案by Oksana Oryekhovska
The problem was solved in 3 steps.
问题分3步解决。
Use %PATH_TO_FX%instead of $PATH_TO_FXin the command line.
Recreate the variables (both system and user) PATH_TO_FXenclosing its value in quotation marks. As the directory "C:\Program Files\Java\javafx-sdk-11.0.1\"contains a space, it caused an error "invalid flag".
Rebooting the computer to update the variables.
在命令行中使用%PATH_TO_FX%而不是$PATH_TO_FX。
重新创建变量(系统和用户)PATH_TO_FX将其值括在引号中。由于目录“C:\Program Files\Java\javafx-sdk-11.0.1\”包含空格,导致错误“无效标志”。
重新启动计算机以更新变量。
回答by Leon
I'm using gradle
and below build.gralde
works fine for me (org.beryx.jlink
is optional to build standalone distribution).
我正在使用gradle
和下面的build.gralde
工作对我来说很好(org.beryx.jlink
构建独立发行版是可选的)。
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.5'
id "org.beryx.jlink" version "2.3.0" //optional for jlink
}
repositories {
mavenCentral()
}
javafx {
modules = [ 'javafx.controls' ]
}
mainClassName = 'gui.Main'
回答by Frank
As JavaFX isn't included in "default" JDK's I found the easiest fix for this kind of issues is to use the LibericaJDK (11+) from Bellsoftware which has the JavaFX included again to make it easier to develop and run JavaFX applications.
由于 JavaFX 不包含在“默认”JDK 中,我发现解决此类问题的最简单方法是使用 Bellsoftware 的 LibericaJDK (11+),它再次包含 JavaFX,以便更轻松地开发和运行 JavaFX 应用程序。
回答by Arilou
I had to also include the 'lib' directory: --module-path %PATH_TO_FX%;%PATH_TO_FX%\lib
to make it compile.
我还必须包含“lib”目录: --module-path %PATH_TO_FX%;%PATH_TO_FX%\lib
以使其编译。