Montag, 21. August 2017

JavaFX on Raspberry - It's still possible!

Hello everybody!

Although Oracle has stopped supporting JavaFX on embedded systems, it is still possible to run JavaFX on Raspberry and no, we do not use the Gluon plugin, even if it is not so bad. If you are looking for a tutorial, you will find only complex tutorials that usually leave out important points or which are still from the time of Oracle's official support. Therefore, I thought to write a quick and easy guide to get JavaFX applications on a Raspberry Pi to run. But let's say that I've tried this on a new Raspberry Pi 3 with Raspbian and therefore does not know if it works on the other boards as well! [go to german version]

Okay, let's go!


Prerequisites Raspberry Pi

  1. Download and compile JavaFX for embedded systems from the OpenJFX project ... or the simple variant: Download the complete Gluon package: http://gluonhq.com/labs/javafxports/downloads/ -> JavaFX Embedded SDK
  2. Now insert the files contained there into the Java SDK of Oracle on the Raspberry. For me this has been found under /usr/lib/jvm/ (from now on called R_JAVA_HOME). To do this, insert all files from the downloaded package into the appropriate folders on the Raspberry:
    1. armv6hf-sdk/rt/lib/ext/* is copied to R_JAVA_HOME/jre/lib/ext/* on the Raspberry
    2. armv6hf-sdk/rt/lib/arm/* is copied to R_JAVA_HOME/jre/lib/arm/* on the Raspberry
    3. armv6hf-sdk/rt/lib/* is copied to R_JAVA_HOME/jre/lib/* on the Raspberry
  3. Now all the necessary libraries are available for the JavaFX application, but you would not see anything when starting a JavaFX application because the standard GPU memory is too small! Therefore, this must be increased to at least 128MB, there are 2 ways to do this and then always have to restart:
    1. Under "Menu" -> "Settings" -> "Raspberry Pi configuration" and then under "Performance".
    2. Or in a terminal run "sudo raspi-config" and then under "Advanced Options" -> "Memory Split"
  4. Done, this was all the Raspberry Pi need to run JavaFX applications! To do this, switch from the X11 desktop (CTRL + ALT + F7) to terminal mode (CTRL + ALT + F1), because JavaFX applications deactivate the X11 and to start the application faster. The Java application is then run with sudo java -jar [FILE], and yes with sudo, because JavaFX otherwise can not use all events correctly.
  5. UPDATE: Meanwhile, I noticed that the screen saver mess up JavaFX applications, therefore disable this! For terminal mode, this can be done in the /etc/kbd/config file. Set the value BLANK_TIME and POWERDOWN_TIME to 0 and restart.

Requirements JavaFX applications


Unfortunately, JavaFX on the Raspberry works differently than on the desktop, therefore a few guidelines to create the JavaFX application:
  1. One window application: Develop the application as an Android or IOS application, so that only one window is displayed, as JavaFX on the Raspberry apparently hates to display additional windows such as the FileChooser.
  2. Be sure to include a way to close the application because CTRL + C does not work! In the JavaFX code, the method is Platform.exit().
  3. For the JavaFX application to run, this must be an executable .jar. I always create this using Maven and the following configuration page: https://javafx-maven-plugin.github.io/
  4. The external libraries need to be copied, e.g. Pi4j with the application to the Raspberry. When using the above JAR plugin, this is the entire [PROJECT_DIRECTORY]\target\jfx\app folder, where the actual JavaFX application is present as .jar and the libs folder containing the external libraries.

That's it so far! Unfortunately, I had no time to deal with it extremely, but in the next few weeks I would like to do so;) But as a small proof here a photo, screenshots on the Raspberry unfortunately did not work because the X11 Desktop is needed by one JavaFX application, which accesses the values of the Raspberry with the help of pi4j:



Have fun with JavaFX on the Raspberry and up next time! =)

Keine Kommentare:

Kommentar veröffentlichen