OpenJFX with RaspberryPi

JavaFX on the Raspberry Pi is a particularly nifty platform to use when you need a nice looking GUI on a regular monitor or a touch-screen. The platform used to ship along with JDK8 for ARM directly and was bundled (last I saw it still was) with out of the box Raspbian.

However, from update 33,  Oracle decided to drop the support for JavaFX on the ARM distribution of their JDK, and stopped shipping it within as well.

However the story doesn’t end here. This change just expedited my idea to give OpenJFX a try, after which I wished I did that way sooner.

My test bed was a RaspberryPi with PiTFT and a touchscreen adapted JavaFX application. Previously I had implemented a headless start of the JavaFX application with fbcp running in the background, and having all the parameters for the touchscreen set right in order to get a nice and correct projection of the FX framebuffer. With OpenJFX, this was no longer needed, cause it is directly supported.

In order to quickly get and use OpenJFX on Raspbian, follow these steps:
– Get and flash a fresh Raspbian image. Make sure you have java and javac present.
– Download a built OpenJFX package (OpenJFX 8u## stable for armv6hf). I used @chriswhocodes OpenJFX builds. There are others listed at the OpenJFX community builds page.
– Extract the contents of the zip file. Copy the /jre/lib folder contents somewhere in your project (I simply copied everything to the project root folder).
– (include the /ext/jfxrt.jar file in your classpath if you compile in an environment without JavaFX present in the JDK)

Finally, when executing your java application, pass the following arguments to the JVM:
-Djava.ext.dirs=dir/to/jfx/ext (I used .dirs=ext because I unpacked the lib contents in the project root)
-Dglass.platform=Monocle
-Dmonocle.screen.fb=/dev/fb1  (only if you use a touchscreen (like the PiTFT)
-Dprism.order=sw (again only for touchscreen, but I’m not really sure. If you experience problems with eventual hardware rendering, use this)

The outcome was pretty pleasant. The UI was looking good and it adapted just fine, although be careful with the dimensions and the general conditions (see tips here).  Also, I had no need to calibrate the screen, it was working correctly from the first run. And last but not least, having not to use fbcp in the background is a huge performance boost and resource saver.

Examples:

Main screen with buttons LED light screen with color picker