且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用JDK 11+运行JavaFX应用程序

更新时间:2022-10-14 23:01:13

JavaFX 11将从Maven Central提供,因此您可以将其包括在内您的项目与任何其他常规依赖项一样,使用Maven:

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

或Gradle:

 依赖项{
compile'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