使用 JDK 11+ 运行 JavaFX 应用程序 [英] Running JavaFX application with JDK 11+

查看:57
本文介绍了使用 JDK 11+ 运行 JavaFX 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我了解 Oracle 的声明,从 JDK 11 开始,JavaFX 将不会包含在 JDK 中,并且将仅作为 OpenJFX 提供.

作为软件开发人员,我必须采取哪些步骤才能让我的 JavaFX 应用程序与 JDK 11+ 一起运行?有什么好的建议吗?是否可以通过 Gradle 使用 OpenJDK?

解决方案

JavaFX 11 将从 Maven Central 获得,因此您可以使用 Maven 将它作为任何其他常规依赖项包含在您的项目中:

<依赖><groupId>javafx</groupId><artifactId>javafx.controls</artifactId><version>11.0.0</version></依赖></依赖项>

或摇篮:

依赖项{编译'javafx:javafx.controls:11.0.0'}

到目前为止(2018 年 6 月),这是

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.

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 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:

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

For now you can download an early release of the JavaFX standalone SDK from here, as announced recently (May 2018).

Note that in any case, you won't need to build nor OpenJDK neither OpenJFX in any case.

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.

You can test them with OpenJDK 10 or 11 EA build that you can get from here.

Sample

If you have a JavaFX Application class:

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

这篇关于使用 JDK 11+ 运行 JavaFX 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆