Running Javafx GUI on the Raspberry Pi

2020-02-06 08:49发布

I have programs that I need to run on the Raspberry Pi and show the output on an lcd connected to the Raspberry Pi.

I have used Java for the programming and JavaFX specifically for the GUI. But on running the program on the Pi, it gives different errors, sometimes not detecting javafx extensions, sometimes not being able to find the main classes.

The OS I'm using for Pi is Raspbian. And performing all the communication on Putty. I have tried using jdk 1.8.0, 1.7.0; ejdk; openjdk. But all seem to give different errors.

It would be really helpful if someone could tell me a way to install the relevant jdk and jre on the Pi, if I format my SD Card and start over with everything.

Also, programs without the use of Javafx run without a glitch on the Pi.

1条回答
霸刀☆藐视天下
2楼-- · 2020-02-06 09:27

As you can read here, the most recent JDK versions for ARM don't include JavaFX.

If you want to use JavaFX in your Raspberry Pi, the solution is adding the missing JavaFX SDK.

If you install the recent Oracle's JDK for ARM from here (select jdk-8u111-linux-arm32-vfp-hflt.tar.gz), then you will need to download the JavaFX SDK from Gluon's site (select JavaFX Embedded SDK for armv6 hard float).

Once you have the file, unzip it, and copy the folders to your JDK.

Assuming you have downloaded armv6hf-sdk-8.60.8.zip to your Pi/Downloads folder, and you have unzip it to a folder armv6hf-sdk, like in the following picture:

Pi ARM JavaFX

using the following commands will allow you moving from command line the files to the JDK required folders. You can use a graphic tool for this as well.

cd Downloads
sudo chown -R root:root armv6hf-sdk
cd armv6hf-sdk
sudo mv lib/javafx-mx.jar /opt/jdk1.8.0_111/lib/
cd rt/lib/
sudo mv j* /opt/jdk1.8.0_111/jre/lib/
sudo mv arm/* /opt/jdk1.8.0_111/jre/lib/arm/
sudo mv ext/* /opt/jdk1.8.0_111/jre/lib/ext/ 

After that you should be able to run Java/JavaFX programs.

If you have a look also at the Gluon IDE plugins, you will be able to create projects on your desktop and deploy them remotely on your Pi (as well as on your desktop and mobile devices). Check the documentation here to set up your build script. And check the sample GluonSQLite here.

查看更多
登录 后发表回答