We help IT Professionals succeed at work.

Running JavaFX on the Raspberry Pi

AttilaB
AttilaB asked
on
3,636 Views
Last Modified: 2018-02-02
I got the default Raspbian OS on a RaspBerry Pi Zero with Oracle Java 1.8.0_65 installed, along with BlueJ IDE, which is also installed by default in the Raspbian OS.

JavaFX is supposed to be run  on a Raspberry Pi, provided it is not a newer version than Oracle Java 1.8.0_65 which was the last version Oracle came out for the ARM processors in the Raspberry Pi, before
they 'axed' ARM support in Java.

In BlueJ there is no choice in what kind of project you would want to run. (Java, JavaFX, etc.) I can only see hardware-specific Raspberry Pi libraries installed if I look at the 'User Libraries' tab of the created project.

If I try to run a simple JavaFX app just to test, it crashes on the first import, which refers to the package:
javafx.application  the basic package that lets you run JavaFX apps.

See screen shots of my problem described above:  
javafx.application does not exist: correct version of Java installedUser Libraries Installed in the Project Preferences
What's happening here? How can I compile and run JavaFX applications on a Raspberry Pi?
Comment
Watch Question

John TsioumprisSoftware & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Are you sure you have installed JDK ? Also i guess is better to install NetBeans as IDE

Author

Commented:
I personally did not install the JDK. If I run java - version from the command line, it talks about Java Runtime Environment. Does that mean this is JRE only and no JDK?

That sounds confusing to me, if I have BlueJ as default installation, and at the same time you cannot compile Java...

How could I test it or find out if JDK is installed?  How would I install it on Raspbian? (Not very familiar with the OS)

Author

Commented:
Can NetBeans even be run on Raspbian? Or should I install something like Ubuntu Mate for ARM to even be able to
run NetBeans on it?
CERTIFIED EXPERT
Top Expert 2016
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I will have to search for jfxrt.jar once I get home, and let you know. Suppose it does not exist: what do I do, just download it from somewhere and add to the 'User Libraries' in the 'BlueJ: Preferences'?

O
CERTIFIED EXPERT
Top Expert 2016

Commented:
I doubt it will be that simple. You really should be installing a JavaFX-supporting package with the package manager if you want to avoid problems

Author

Commented:
OK. I don't remember seeing a package manager on the Raspbian OS. According to my web search I could install Synaptic: just by sudo apt-get install synaptic.

Will that show me though if the correct Java SDK is installed?

According to my web search I can install the SDK as such:
sudo apt-get update 
    sudo apt-get install oracle-java8-jdk
   

Open in new window


But, after this install, it will only give me something back about the Runtime Environment, not the SDK:
 java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode)

Open in new window


Will see.
CERTIFIED EXPERT
Top Expert 2016

Commented:
From the brief look i had, you can't use the repo's JDK, so you probably have the one you need

javac

Open in new window

is what you need to try to run if you want to do development on the Pi

Author

Commented:
I will try your command line compile suggestion when I get home. It is confusing though.

Why do I have a Java IDE, with all the functionality, including making JAR files if I cannot compile source code?

 I will also try a regular Java 'Hello World' compile on it just to retain my sanity, when I get home.
CERTIFIED EXPERT
Top Expert 2016

Commented:
I don't know BlueJ, so don't know if it has its own compiler or not. If not, you need to have one (javac). Personally, i don't see why anyone would want to do Java development without  a standalone compiler

Author

Commented:
CEHJ, you have provided half the solution: No trace of jfxrt.jar on the system, after I searched for it per your suggestion..

On the other hand, I could make a simple 'Hello Word' app that included JOptionPane out of Swing. I could compile and run it out of BlueJ,
and also create a runnable jar file. See screen shots:java Compiles and RunsThen, the jar file running:Jar run from the command line
I have one more question: Why do they say JavaFX is supported, if it is not there?

Author

Commented:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/RaspberryPiFX/raspberryfx.html#section5s3


Ok. Here Oracle says, that you can just simply run jar files that contain compiled JavaFX code by copying it from another system.
I just did that, copied such a jar file with JavaFXthat ran fine in Windows with Java 8 installed.
The error message: Could not find or load main class.
Clearly, there is no trace of JavaFX on this Pi.  But why?
CERTIFIED EXPERT
Top Expert 2016

Commented:
We can try to locate it on the Pi. Can you please begin with

sudo updatedb

Open in new window

John TsioumprisSoftware & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:

Author

Commented:
CEHJ, I will start on locating JavaFX with updatedb, etc. once I get home today.

John, yes I know this tutorial. Some of it I could do, but some of it like setting a static IP address I could not due to
network issues here. I should not have to go through this step by step and remotely run JavaFX to have it running
on the pi, I would think.

Author

Commented:
Well, this is really messy: I was just reading one of the Raspberry Pi online forums, and somebody with suggestions says:
"The Oracle JDK will not bundle JavaFX"    Quite a shock: Is it Java 8 or not Java 8 then?

They say: You need to install something like: OpenJFX for Debian

https://packages.debian.org/source/testing/openjfx

Then, of course at this point Oracle doesn't want to support the Raspberry Pi any more, with future releases.

This looks even more experimental than I thought.  What I am going to do, is I will test 'Old Style Java' Swing with a more sophisticated application than what I did with Hello World with a JOptionPane pop-up yesterday. If Swing does work I  will use Swing and old style Java with the installed hardware libraries (I/O control libraries)  to make my 'Java gadget' with the RPi.

If it doesn't fully work, than I will start going / experimenting the OpenJFX way.

I will award your points / close question after I find this out.
CERTIFIED EXPERT
Top Expert 2016

Commented:
You're definitely on safer ground with Swing. But you could give openjfx a try
http://gluonhq.com/download/javafx-embedded-sdk/ maybe
CERTIFIED EXPERT
Top Expert 2016

Commented:
btw, you will find jfxrt.jar in that download

Author

Commented:
Thanks. I may try Gluon too. Especially if Swing and classic Java doesn't work completely. I am just a little scared about possible speed issues. RPi is small and cheap, especially the 'RPi zero' model I am using that fits inside your palm.

I would think Gluon would slow it down, somewhat.
CERTIFIED EXPERT
Top Expert 2016

Commented:
If you're using a Pi Zero, i'd guess any Java would be problematic.

Author

Commented:
Will try to test with some real applications and let you know. If worse comes to worse I can upgrade to the latest, fastest, most memory RPi. I just wanted to use the 'smallest possible box' for one dedicated Java app running on it with a touch screen. May try Gluon too.
CERTIFIED EXPERT
Top Expert 2016

Commented:
What leads you to want Java on the Pi?

Author

Commented:
I have only done Java, VB6 and some C++. I tried Python and disliked it. The RPi books seem to be loaded with Python... I don't really want to use it.

Author

Commented:
I tried a desktop application with Java and Swing originally made for Windows out of 6 classes and a single-class app used with a couple of JAR libraries for JFreeChart on RPi.

 It also contained reading and processing files and outputting the processed files. Everything worked without any significant deterioration in performance, using RPi Zero.

The screen fonts are messed up, but that can happen if you try to run something you inGluontended for Windows under Linux.

A little 'bland' looking but runs fine, see screenshots:6-class file processing app for Windows runningJFreeChart tested with 2 jar files

Author

Commented:
Thanks for all your help. I think I will see some Youtube videos about Gluon and I will try that too.
For more exciting looks.

But it does look like I will be fine with Java and Swing on the Raspberry Pi Zero.

Author

Commented:
Which folder would I copy jfxswt.jar to have it in the JDK?
John TsioumprisSoftware & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
I think you need to open a new question given the fact that you have awarded the points .
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.