使用 JDK 11+ 运行 JavaFX 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50828975/
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
Running JavaFX application with JDK 11+
提问by Hannes
If I understand Oracle's announcments JavaFX won't be included to the JDK beginning with JDK 11 and will be only available as OpenJFX.
如果我了解 Oracle 的公告,从 JDK 11 开始,JavaFX 将不会包含在 JDK 中,并且只能作为 OpenJFX 使用。
What steps do I have to make as an software developer to allow my JavaFX application to be run with JDK 11+? Is there any good adivce? Will be OpenJDK available via Gradle?
作为软件开发人员,我必须采取哪些步骤才能让我的 JavaFX 应用程序与 JDK 11+ 一起运行?有什么好的建议吗?是否可以通过 Gradle 使用 OpenJDK?
采纳答案by José Pereda
JavaFX 11 will be available from Maven Central, so you will be able to include it in your project as any other regular dependency, using Maven:
JavaFX 11 可从 Maven Central 获得,因此您可以使用 Maven 将它作为任何其他常规依赖项包含在您的项目中:
<dependencies>
<dependency>
<groupId>javafx</groupId>
<artifactId>javafx.controls</artifactId>
<version>11.0.0</version>
</dependency>
</dependencies>
or Gradle:
或摇篮:
dependencies {
compile 'javafx:javafx.controls:11.0.0'
}
So far (June 2018), this is work in progress, but it should be ready at the time of the JDK 11 release.
到目前为止(2018 年 6 月),这项工作正在进行中,但应该在 JDK 11发布时准备就绪。
For now you can download an early release of the JavaFX standalone SDK from here, as announced recently (May 2018).
现在,您可以从这里下载 JavaFX 独立 SDK 的早期版本,正如最近(2018 年 5 月)所宣布的那样。
Note that in any case, you won't need to build nor OpenJDK neither OpenJFX in any case.
请注意,在任何情况下,您都不需要构建 OpenJDK,也不需要 OpenJFX。
You will find a bunch of jars with the different modules like javafx.base.jar
or javafx.controls.jar
, as well as the required native libraries for your platform.
您会发现一堆带有不同模块的 jar,例如javafx.base.jar
或javafx.controls.jar
,以及您的平台所需的本机库。
You can test them with OpenJDK 10 or 11 EA build that you can get from here.
您可以使用从这里获得的 OpenJDK 10 或 11 EA 构建来测试它们。
Sample
样本
If you have a JavaFX Application class:
如果您有 JavaFX 应用程序类:
public class JavaFX11 extends Application {
@Override
public void start(Stage stage) throws Exception {
Scene scene = new Scene(new StackPane(new Label("JavaFX 11")), 300, 200);
stage.setScene(scene);
stage.show();
}
}
you can compile it:
你可以编译它:
<path.to>/jdk-11.jdk/Contents/Home/bin/javac --module-path <path.to>/javafx-sdk-11/lib/ --add-modules=javafx.controls -d class/ src/<package.name>/JavaFX11.java
and run it:
并运行它:
cd class
<path.to>/jdk-11.jdk/Contents/Home/bin/java --module-path <path.to>/javafx-sdk-11/lib/ --add-modules=javafx.controls <package.name>.JavaFX11