The "javafx might not be present" problem

Mark Raynsford org.openjdk at
Fri Feb 9 13:29:50 UTC 2018


I've been using Swing for many years. One of the things I like most
about it is that it's essentially guaranteed to be present in any Java
SE installation, and although it's a little outdated aesthetically, it
works well and continues to work well.

I've been exploring the possibility of migrating to JavaFX on and off,
but the biggest showstopper for me is that JavaFX may not actually be
present in any given user's installation. If someone installs the
jre9-openjdk package on Arch Linux, for example, they don't get JavaFX.
If they install the java-openjfx package, they do (although Arch only
offers JavaFX 8 right now).

I'm migrating to Java 9 modules, and all new projects will be fully
modular projects. In the olden days (pre Java 9), it was possible to
detect if JavaFX was present with a reflection hack:

try {
  Class jfxPanel = classLoader.loadClass("javafx.embed.swing.JFXPanel");
  isJavaFxAvailable = true;
} catch (ClassNotFoundException e) {
  isJavaFxAvailable = false;

The idea being that you could at least display a friendly error message
to the user explaining that they need to install JavaFX if they're
using OpenJDK.

But obviously in a Java 9 project, that's not going to work: You'd need
to specify a "requires" clause on the JavaFX modules, and if they
weren't present, the VM wouldn't even start up so the above check
wouldn't get a chance to run.

For applications, I could probably try to bundle JavaFX with them
(although there may be licensing issues there). For libraries, I'm out
of luck. The only apparent option there is for me to pick a set of
Maven coordinates like "org.openjdk:javafx:8.0" and specify those in my
libary's POM file (and assume that the user is smart enough to deploy
JavaFX to a local repos to use it).

I suppose what I'm really saying is: When (if ever) can I expect JavaFX
to be present unconditionally with OpenJDK installs? I probably can't
migrate to JavaFX until that day...

Mark Raynsford |

More information about the openjfx-dev mailing list