Developer preview for JavaFX inside a web browser


One of the great things about JavaFX is that user interfaces created with the JavaFX APIs can be rendered on different platforms, with different architectures and operating systems. JavaFX applications can be executed on desktop systems (with MacOS, Windows, Linux) but also on mobile and embedded devices (e.g. iOS, Android, Raspberry Pi, e-paper).

Gluon is now releasing a developer preview that shows how you can run your JavaFX application inside a browser. The approach we follow is very similar to how JavaFX applications are executed as standalone images on other platforms.

A long time ago, the strategy for running Java applications relied on the availability of a Java Runtime Environment (JRE) on the device that was expected to run the application. That works somehow for desktop systems, but it requires users to upgrade and maintain the JRE. On mobile devices, this is not just annoying, it is a showstopper. Users download self-contained apps on mobile devices, not libraries or dependencies. In today’s web context, there is no JRE anymore.

Java still has a prominent place on those systems, but instead of pushing the JRE to all devices, we learned that we have to bundle our applications with the relevant dependencies, including the parts of the JRE that are relevant. This is what Gluon Substrate is doing: the Java developer focuses on his application code (in Java or a JVM language, with a JavaFX user interface), and Gluon Substrate translates or transpiles the code into a format understood and accepted by the target device.

For targeting web devices, Gluon Substrate now transpiles Java bytecode into JavaScript code using the fantastic bck2brwsr transpiler. This transpiler covers not only your application code and its dependencies, but also the JavaFX runtime code, which is transpiled into a javascript file per module.

The architecture of the JavaFX platform decouples the developer-facing APIs from the low-level rendering. For making it possible to render inside a webcontext, we created a JavaFX rendering pipeline that leverages WebGL. Gluon Substrate combines all of this, and outputs a set of HTML and JavaScript files.

This work if far from complete. The basic functionality is working, as you can see in the HelloWeb demo.

We realize there is much work left. Therefore, we now release a developer preview, so that developers understand how the system works, and we highly welcome contributions. We made some technical information available in a specific repository: https://github.com/gluonhq/promise.

We hope that you’re as excited as we are about rendering JavaFX inside the web browser.