23

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?

Hannes
  • 5,002
  • 8
  • 31
  • 60
  • Just install openjfx. – mr mcwolf Jun 13 '18 at 04:33
  • What does 'install' mean in that context? Do I need to ship OpenJFX as well with my application? – Hannes Jun 13 '18 at 04:53
  • yes, it must. in the same way you are dependent on JRE. whether you will make a JRE (and OJFX) manual installation or will customize JRE (build with jlink) you judge yourself. – mr mcwolf Jun 13 '18 at 05:40
  • 2
    So far I only have to tell users to install a JDK or JRE. Moreover, Java is usually already installed on just about any machine out there. So now when I want to use JavaFX starting from JDK 11, I need users to do another difficult platform-dependent install? This is such a step backwards. Native libraries can be packaged much more smartly and in a platform-independent way. See e.g. the OSHI project. Some criticism in the direction of Oracle is in order. – Stefan Reich Nov 15 '18 at 00:54
  • 1
    @StefanReich I do not agree. Jigsaw allows you to bundle the JRE with your application and it can be run on systems which have no JRE installed yet. – Hannes Nov 15 '18 at 07:36

3 Answers3

20

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

JavaFX 11

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • Thank you so much for your answer. It's reassuring to keep using JavaFX! Under what license will the binaries be distributed? – Hannes Jun 13 '18 at 15:55
  • If you check the binaries, there are license files for each modules. So far it seems it will be the GNU General Public License, version 2, with the Classpath Exception. – José Pereda Jun 13 '18 at 16:01
  • 1
    Will we have to always run the applications with `/jdk-11.jdk/Contents/Home/bin/java --module-path /javafx-sdk-11/lib/ --add-modules=javafx.controls .JavaFX11`? – krentm Nov 01 '18 at 20:43
  • See the [getting started guide](https://openjfx.io/openjfx-docs/), it will depend on what build tools you use. – José Pereda Nov 01 '18 at 20:46
3

OpenJFX bundled with your app

The Answer by José Pereda is correct about bundling JavaFX libraries within your app.

OpenJFX bundled with Java

An alternative is for your users to have installed an implementation of Java on their machines that includes the OpenJFX (JavaFX) libraries. This approach may be unworkable for apps broadly distributed to the public. But for apps within a controlled environment such as an enterprise or institution, this might be beneficial.

OpenJXF is a sub-project on the OpenJDK project. But JavaFX technology is not defined as a part of Java SE. So some vendors choose to bundle OpenJFX with their OpenJDK-based products, and some do not.

At least two vendors currently ship an implementation of Java SE with OpenJFX included. Both are built on top of OpenJDK. Both have back-ported OpenJFX to Java 8.

Here is a flowchart graphic I made to help in choosing a vendor of an implementation of Java. Notice the OpenJFX bundled? branch at the bottom.

enter image description here

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
2

You can use LibericaJDK instead of OpenJDK. It bundled with JavaFX which can save you a lot of configurations. https://bell-sw.com/pages/downloads/#/java-11-lts Just need to download the "Full JDK".

len
  • 376
  • 2
  • 19