Javafx and Openjdk

JavaFX and OpenJDK

JavaFX is part of OpenJDK

The JavaFX project itself is open source and is part of the OpenJDK project.

However, the OpenJDK project includes many projects, including incubating projects and other projects, such as OpenJFX, whose source and implementation are not shipped as part of some JDK/JRE distributions (e.g. Oracle JDK 11+ implementations and many open-source JDK Linux package installations do not include JavaFX runtimes).

Modern JavaFX distributions are modules

JavaFX is not part of most JDK 11+ downloads, it is usually downloaded by developers as modules or a separate SDK.

Specifically for JavaFX 11+, as detailed on the https://openjfx.io site:

JavaFX runtime is available as a platform-specific SDK, or as a number of jmods, or as a set of artifacts in Maven Central.

This means that JavaFX can be used from any modern JDK running on a supported platform, by including the appropriate JavaFX modules (available from openjfx or Maven Central) on the runtime module path.

All JavaFX modules available from openjfx are open source implementations that contain no closed source code.

For distribution of JavaFX-based applications to end-users, it is advised to package a run-time image distribution based on the JDK and JavaFX modules + required dependent library code and application code. A full discussion of this packaging is out of scope for this answer, but one can create a distribution based purely on open-source JDK+JavaFX+library+application code if desired. See the openjfx.io documentation on run-time images for some more (though not comprehensive) information on this.

Update Sep 2021

Also, see the related question:

  • JavaFx in oracle JDK 8 is same as openjfx 8 versions or not? what is the relationship between javafx in oracle jdk 8 and openjfx8?

Which covers information regarding Java 8 and also some later versions.

Update Dec 2019

For current information on how to use Open Source JavaFX, visit https://openjfx.io. This includes instructions on using JavaFX as a modular library accessed from an existing JDK (such as an Open JDK installation).

The open source code repository for JavaFX is at https://github.com/openjdk/jfx.

At the source location linked, you can find license files for open JavaFX (currently this license matches the license for OpenJDK: GPL+classpath exception).

The wiki for the project is located at: https://wiki.openjdk.java.net/display/OpenJFX/Main

If you want a quick start to using open JavaFX, the Bellsoft's Liberica JDK distributions provide pre-built OpenJDK binaries that include OpenJFX for a variety of platforms.

For distribution as self-contained applications, Java 14 is scheduled to implement JEP 343: Packaging Tool, which "Supports native packaging formats to give end users a natural installation experience. These formats include msi and exe on Windows, pkg and dmg on macOS, and deb and rpm on Linux.", for deployment of OpenJFX based applications with native installers and no additional platform dependencies (such as a pre-installed JDK).


Older information that may become outdated over time

Building JavaFX from the OpenJDK repository

You can build an open version of OpenJDK (including JavaFX) completely from source which has no dependencies on the Oracle JDK or closed source code.

Update: Using a JavaFX distribution pre-built from OpenJDK sources

As noted in comments to this question and in another answer, the Debian Linux distributions offer a JavaFX binary distibution based upon OpenJDK:

  • https://packages.qa.debian.org/o/openjfx.html

  • Install via:

    sudo apt-get install openjfx

(currently this only works for Java 8 as far as I know).

Differences between Open JDK and Oracle JDK with respect to JavaFX

The following information was provided for Java 8. As of Java 9, VP6 encoding is deprecated for JavaFX and the Oracle WebStart/Browser embedded application deployment technology is also deprecated. So future versions of JavaFX, even if they are distributed by Oracle, will likely not include any technology which is not open source.

Oracle JDK includes some software that is not usable from the OpenJDK. The components that relate to JavaFX:

  • The ON2 VP6 video codec, which is owned by Google and Google has not open sourced.
  • The Oracle WebStart/Browser Embedded application deployment technology.

This means that an open version of JavaFX cannot play VP6 FLV files. This is not a big loss as it is difficult to find VP6 encoders or media encoded in VP6.

Other more common video formats, such as H.264 will playback fine with an open version of JavaFX (as long as you have the appropriate codecs pre-installed on the target machine).

The lack of WebStart/Browser Embedded deployment technology is really something to do with OpenJDK itself rather than JavaFX specifically. This technology can be used to deploy non-JavaFX applications.

It would be great if the Open Source community developed a deployment technology for Java (and other software) which completely replaced WebStart and Browser Embedded deployment methods, allowing a nice light-weight, low impact user experience for application distribution. I believe there have been some projects started to serve such a goal, but they have not yet reached a high maturity and adoption level.

Personally, I feel that WebStart/Browser Embedded deployments are legacy technology and there are currently better ways to deploy many JavaFX applications (such as self-contained applications).

Update Dec, 2019:

An open source version of WebStart for JDK 11+ has been developed and is available at https://openwebstart.com.

Who needs to create Linux OpenJDK Distributions which include JavaFX

It is up to the people which create packages for Linux distributions based upon OpenJDK (e.g. Redhat, Ubuntu etc) to create RPMs for the JDK and JRE that include JavaFX. Those software distributors, then need to place the generated packages in their standard distribution code repositories (e.g. fedora/red hat network yum repositories). Currently this is not being done, but I would be quite surprised if Java 8 Linux packages did not include JavaFX when Java 8 is released in March 2014.

Update, Dec 2019:

Now that JavaFX has been separated from most binary JDK and JRE distributions (including Oracle's distribution) and is, instead, available as either a stand-alone SDK, set of jmods or as a library dependencies available from the central Maven repository (as outlined as https://openjfx.io), there is less of a need for standard Linux OpenJDK distributions to include JavaFX.

If you want a pre-built JDK which includes JavaFX, consider the Liberica JDK distributions, which are provided for a variety of platforms.

Advice on Deployment for Substantial Applications

I advise using Java's self-contained application deployment mode.

A description of this deployment mode is:

Application is installed on the local drive and runs as a standalone
program using a private copy of Java and JavaFX runtimes. The
application can be launched in the same way as other native
applications for that operating system, for example using a desktop
shortcut or menu entry.

You can build a self-contained application either from the Oracle JDK distribution or from an OpenJDK build which includes JavaFX. It currently easier to do so with an Oracle JDK.

As a version of Java is bundled with your application, you don't have to care about what version of Java may have been pre-installed on the machine, what capabilities it has and whether or not it is compatible with your program. Instead, you can test your application against an exact Java runtime version, and distribute that with your application. The user experience for deploying your application will be the same as installing a native application on their machine (e.g. a windows .exe or .msi installed, an OS X .dmg, a linux .rpm or .deb).

Note: The self-contained application feature was only available for Java 8 and 9, and not for Java 10-13. Java 14, via JEP 343: Packaging Tool, is scheduled to again provide support for this feature from OpenJDK distributions.

Update, April 2018: Information on Oracle's current policy towards future developments

  • The Future of JavaFX and Other Java Client Roadmap Updates by Donald Smith, Sr. Director of Product Management, Oracle.
  • Java Client Roadmap Update - March 2018 an Oracle White Paper.

How to use JFX/OpenFX with OpenJDK 8

Is there any javafx/OpenJFX dependency which can be used directly in the pom file so that it works with OpenJDK 8?

AFAIK, no. There are org.openjfx artifacts for OpenJFX 11 onwards, but they won't work with Java 8. (The class file version will be wrong.)

Or any workaround (without installing anything) which works with OpenJDK 8?

I think you will need to build your own copy of OpenJFX from source, and (touch wood) "package it" with your application1.

(The following is purely based on reading the OpenJFX build instructions. I have not tried this out.)


So if you want to build a stand-alone OpenJFX 8 for use with OpenJDK 8, then you should try the following build instructions on the OpenJFX wiki:

  • Building OpenJFX 8u

The result of the build is (apparently) a ZIP file that is designed to be "overlayed" onto a JRE installation.

You may be able to repackage that into JARs and native libraries that you can include in your application.


For OpenJFX 9 and later, the build instructions are here:

  • Building OpenJFX

Apparently, for N >= 9, OpenJFX version N is supposed to be supported for OpenJDK N and OpenJDK N - 1. So if that is accurate, you should be able to build OpenJFX 9 for OpenJDK 8. On the other hand, the build instructions talk about generating modules, and module support is only available in Java 9 and later. However it is still worth a try (IMO).


1 - Options include 1) creating a custom Debian package(s) (or RPMs) ... analogous to the existing Ubuntu packages, 2) incorporating the relevant classes and native libraries into your application JAR, or 3) adding them to your applications classpath and library load path. You may need to experiment.

Openjdk-17.0.2 with javafx in termux

For faster development and improvement, JavaFX was excluded from Java SE since OpenJDK 11, and now managed as a separate project (see https://github.com/openjdk/jfx). If you want to use JavaFX with Java SE, you need to download JavaFX jmods/SDK from https://www.gluonhq.com/products/javafx, and put them in module path / class path when building.

However, the official builds of JavaFX can't be used in Termux because the architecture is incompatible. There is already a package request in Termux's official packages Github repository (see https://github.com/termux/termux-packages/issues/10225), if this package is built and added into Termux, then you can install it simply by apt install openjfx and use it in your build.

Why does JavaFX not work under OpenJDK 17 from Homebrew?

JavaFX has never been an official part of the Java platform.

For a while, Oracle was bundling the JavaFX libraries with their own Oracle JDK product, but later stopped. Those libraries were a bonus, an extra, not required by the Java specifications.

Keep in mind that several vendors provide Java implementations. At least two of them provide a variant that includes the OpenJFX libraries implementing JavaFX, if that is what you want:

  • ZuluFX by Azul Systems
  • LibericaFX from BellSoft

Last time I looked, both of those products were available for macOS on both Intel Macs and Apple Silicon Macs.

Alternatively, you can bundle the OpenJFX libraries within your app.

How do I get Java FX running with OpenJDK 8 on Ubuntu 18.04.2 LTS?

The hint from

https://github.com/JabRef/help.jabref.org/issues/204

helped. The commands:

apt purge openjfx
apt install openjfx=8u161-b12-1ubuntu2 libopenjfx-jni=8u161-b12-1ubuntu2 libopenjfx-java=8u161-b12-1ubuntu2
apt-mark hold openjfx libopenjfx-jni libopenjfx-java

fixed the problem. Many thanks to https://github.com/Druidefix for this. (If you'd like to answer this yourself I'll happily delete my own answer ...)

OpenJdK 8 - Can't compile package javafx.util does not exist

tl;dr

Either:

  • Develop/deploy on a JDK that includes the OpenJFX libraries.
  • Add the OpenJFX libraries to your Java project.

Details

JavaFX has never been an official part of Java SE.

For a while Oracle included their JavaFX library along with their JDK. They later ceased bundling.

You need to add an implementation of JavaFX to your project. You’ll find such an implementation in OpenJFX. This open-source project is housed as a subproject on the OpenJDK project, co-led by Gluon and Oracle.

Use your dependency manager of choice, such as Apache Maven or Gradle, to add the OpenJFX library to your project. Below I put Maven repo links for OpenJFX 11 through 17, but those require Java 11+. I have not found any Maven repo links for JavaFX/OpenJFX for Java 8.

Alternatively, you can develop on, and deploy to, a JDK that bundles the OpenJFX libraries. At least two vendors offer an edition of their JDK product with such a bundle:

  • ZuluFX by Azul Systems
    • See this downloads list for Java 8 on macOS, Linux, & Windows. Notice the Java Package filter field at top of downloads list.
  • LibericaFX by BellSoft
    • On the Downloads page, choose the Full option for an edition bundling OpenJFX. Available for Java 8 on macOS, Linux, & Windows.

If at all possible, consider moving on from Java 8. I suggest moving to the later LTS versions of Java, 11 and 17, as well as the latest LTS version of OpenJFX, 17, which requires Java 11 or later. Both Java and JavaFX have evolved greatly in recent years. This evolution includes the jlink and jpackage tooling to package your JavaFX app as single "double-clickable" app that includes the minimal parts of a JDK/JVM needed to run on a specific platform.

Versions

For OpenJFX versions 11 through 17, Java 11 or later is required/recommended. See Release Notes.

Maven links for OpenJFX 11 through 18 can be found here, and on other Maven repositories.

Source code for OpenJFX versions 14 through 18 can be found on GitHub site for OpenJDK. Source code for older versions 2, 8, 9, and 10 can be found on the read-only Mercurial repository of OpenJDK.



Related Topics



Leave a reply



Submit