B4J Tutorial [Raspberry Pi] One Window Application with JavaFXPorts

With Gluon JavaFXPorts it is possible to run JavaFX on Embedded like the Raspberry Pi.
JavaFXPorts is the name of the open source project maintained by Gluon.
The JavaFX application runs as a one window, similiar to an Android app.

Below setup has been tested with some simple B4J UI-Applications (Hello World, GPIO switch LED on/off) running on a Raspberry Pi 3 with the latest Raspian Jessie version (using Pixel) - Status 20170405.

Notes
  • For downloads, a PC has been used to transfer files with WinSCP to the respective Raspberry Pi folder.
  • Versions used: B4J v5.00, Java JDK 8u121, Gluon armv6hf SDK 8.60.8, WinSCP 5.9.4, B4J-Bridge v1.20.
  • B4J-Bridge is an essential tool to test the application.
  • An alternative to this solution, is to use B4A with Android Things - read here.
  • Want to use a one window UI-Application for controlling (Bluetooth BLE) the upcoming Brixo Building Blocks (Brixo Home)
Development Hints
Ensure to define a method to close the one window UI-Application, like a Close Button.

When using external libraries (e.g. jPi4J), set the Project Attribute MergeLibraries to True.
B4X:
#Region Project Attributes
  #MergeLibraries: True
#End Region
Pixel ScreenSaver does not work when the one window UI-Application is running.
Workaround: Not found. An option could be to trigger, via jShell, the command vcgencmd display_power 0 | 1 or to use a timer and check for inactivity.

When screen size maximized, the cursor changes from default to a black cursor.
Workaround: Set the screen size to maximum - an offset of 20. This might depend on the monitor used.

Memory Error glGetError 0x505 or the B4J IDE logs, like
java.lang.NullPointerException
at com.sun.prism.impl.ps.PaintHelper.initGradientTextures(PaintHelper.java:131)
at com.sun.prism.impl.ps.PaintHelper.getGradientTexture(PaintHelper.java:141)
...
Workaround: Change the Raspberry Pi memory split from default 64 to 128 or 256 MB.

Installation
Download and unpack Java JDK

Logon to the Raspberry Pi as User Pi.
Create a folder: mkdir /home/pi/java.
Set the folder: cd /home/pi/java.
Download from Oracle jdk-8u121-linux-arm32-vfp-hflt.tar.gz or higher version if available.
Copy jdk-8u121-linux-arm32-vfp-hflt.tar.gz to /home/pi/java: cp jdk-8u121-linux-arm32-vfp-hflt.tar.gz /home/pi/java
Unpack jdk-8u121-linux-arm32-vfp-hflt.tar.gz to /opt: sudo tar zxvf jdk-8u121-linux-arm32-vfp-hflt.tar.gz -C /opt

Set Java Alternatives
sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_121/bin/javac 1
sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_121/bin/java 1

sudo update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac):
Select choice 1, resulting in message below.
update-alternatives: using /opt/jdk1.8.0_121/bin/javac to provide /usr/bin/javac (javac) in manual mode

sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java):
Select choice 1, resulting in message below.
update-alternatives: using /opt/jdk1.8.0_121/bin/java to provide /usr/bin/java (java) in manual mode

Check the Java versions
pi@raspberrypi:~/java $ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) Client VM (build 25.121-b13, mixed mode)
pi@raspberrypi:~/java $ javac -version
javac 1.8.0_121

Copy JavaFXPorts
Create folder /home/pi/java/.
Download from Gluon armv6hf-sdk-8.60.8.zip or higher version if available.
Copy the required files:
sudo cp /home/pi/java/armv6hf-sdk/rt/lib/ext/jfxrt.jar /opt/jdk1.8.0_121/jre/lib/ext/
sudo cp /home/pi/java/armv6hf-sdk/rt/lib/arm/* /opt/jdk1.8.0_121/jre/lib/arm/
sudo cp /home/pi/java/armv6hf-sdk/rt/lib/javafx.platform.properties /opt/jdk1.8.0_121/jre/lib
sudo cp /home/pi/java/armv6hf-sdk/rt/lib/javafx.properties /opt/jdk1.8.0_121/jre/lib
sudo cp /home/pi/java/armv6hf-sdk/rt/lib/jfxswt.jar /opt/jdk1.8.0_121/jre/lib

Check libpango and libgtk2
(when using the latest Raspian Jessie these should be up-to-date).
sudo apt-get install libpango-1.0-0:armhf libpangoft2-1-0:armhf
sudo apt install libgtk2.0-0

Install the B4J Bridge
Create a folder /home/pi/b4j
Set the folder: cd /home/pi/b4j
Get the B4J Bridge:
wget http://www.b4x.com/b4j/files/b4j-bridge.jar

Test the B4J Bridge
Start the B4J-Bridge (to test if running) in a Terminal (open via WinSCP with Ctrl-P):
sudo java -jar b4j-bridge.jar
B4J-Bridge v1.20
Waiting for connections (port=6790)...
My IP address is: 192.168.0.21
FTP Server started: ftp://192.168.0.21:6781
Start B4J-Bridge with -disableftp to disable.
Connected!
Starting program
 

rwblinn

Well-Known Member
Licensed User
Longtime User
A few personal thoughts:
JavaFXPorts
is one of the Community Builds of the OpenJDK with target focus for Mobile (Gluon ported the JavaFX Framework for Android & iOS) & Embedded (=Raspberry Pi, Pine64 ...).

There reason, why I explored JavaFXPorts, was for Embedded on Raspberry Pi ONLY.

JavaFXPorts runs on the Raspberry Pi with the latest Java ARM version, whereas JavaFX might have issues running (see the thread) ... but must say that I have not tested any latest JavaFX (=OpenJDK) versions on the Raspberry Pi.
JavaFXPorts updates might have a delay if major changes / bug fixes are made by the OpenJDK Census ... this depends on level of commercial support.
JavaFXPorts Website is easy to navigate, documentation and to find the latest downloads.

Open for any other thoughts or experience --- probably it is a matter of taste ...
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…