JavaFX on Raspberry Pi – 3 Easy Steps
steveonjava | December 18, 2012The long awaited early access of JavaFX on Raspberry Pi is finally out. This is a great platform for doing small embedded projects, a low cost computing system for teaching, and great fun for hobbyists. It only costs $35 for the Model B version with 512MB RAM, 700MHz ARM processor and I/O for HDMI, Composite, Audio, Ethernet, and 2 USB ports.
So what can you do with JavaFX on a Raspberry Pi? A great example is the digital signage that we put together for Devoxx showing the conference schedule flying by on animated space ships:


Update: And if you are not convinced that Java is performant on the Pi, check out Rich Bair’s post on fxexperience.com: http://fxexperience.com/2012/12/javafx-on-raspberry-pi/
So if you are convinced to get started, there are 3 easy steps to get JavaFX running on your Pi:
- Install Linux on your Raspberry Pi
- Download and copy Java/JavaFX 8 to your Pi
- Deploy and run JavaFX apps on your Pi
This does assume you have a Pi… For questions about where to get a Pi, how to power it, etc., I would recommend checking out the Raspberry Pi Site.
Step 1 – Installing Linux on Your Raspberry Pi
The latest Java 8 release is hard float, which is a good thing, because it gives you better performance and the recommended Raspberry Pi build is also hard float. Stay away from anything that says soft, softfp, etc., because it will be incompatible with the hard float JVM.
Note: Why all this fuss over floating point? Well, low power embedded systems skip the floating point hardware to save cost (e.g. ARM Cortex M0-M3). Fortunately the ARMv6 chip used in the Raspberry Pi has real floating point support.
To setup Linux on your SD card, you will need a Windows, Mac, or Linux desktop with an SD Card Reader/Writer. The distribution you want is the latest Raspbian Wheezy hard float build, which is the recommended install on the Raspberry Pi download site:
http://www.raspberrypi.org/downloads
To burn the image you have a few options, which are detailed here, but basically boil down to:
- Windows: Use Win32DiskImager
- Mac: Use the RPi-sd Card Builder
- Linux: Use the dd command
Once your SD card is created, take your Raspberry Pi out of the box, pop in the SD Card, hook it up to a monitor or TV lying around your place, and plug it up to a nice usb power brick (5V 700mA or greater).
Warning: Order Matters! – If you don’t hook up an HDMI monitor before powering on the Pi, it assumes composite. This means if the lights are flashing but you get a blank screen, you should try rebooting the Pi (by unplugging and replugging it in).
At this point, your Pi should bootup and show you the Raspberry Pi config screen. There are some things you might want to consider tweaking here, including:
- CPU/GPU memory split – Give the GPU at least 128MB of ram so graphical heavy apps will run better (important for JavaFX!)
- Change the locale/keyboard/timezone – Default settings are for the UK, so everyone else should change these or you will be cursing at your keyboard when trying to type punctuation!
- Overscan – If your display has black bars around the edges, turn this off so you can use the full resolution.
- Expand root filesystem – It can do an online resize of your card to use the full space (default image has a tiny 2GB root partition). Highly recommended, but expect this to take a while on a large card.
- SSH – Turn this on if you want to access your Pi over the network (this is the only way to shut down rogue JavaFX processes short of rebooting)
In the official JavaFX Raspberry Pi docs they also recommend hacking the framebuffer to be 720p in the config file (/boot/config.txt) by uncommenting these lines:
framebuffer_width=1280 framebuffer_height=720
This is not strictly required, but will give you better performance since the Pi is pushing fewer pixels. If you are going to do this, you might also want to force the Pi to run in 720 resolution as well to avoid pixel upscaling. Don’t try hacking the display settings unless you know what you are doing (and have an ssh terminal to login remotely in case you kill the display). For more info about the HDMI display nodes, check out the docs here.
Step 2 – Download and Copy Java/JavaFX 8 to Your Pi
You can download a Raspberry Pi compatible Java/JavaFX 8 build here:
http://jdk8.java.net/fxarmpreview
If your Pi is hooked up to the network via ethernet you can download it directly to the device. Otherwise copy it over using sftp (via ssh) or sneakernet (a USB key).
Once you have it downloaded, you can unzip it to a location of your choice:
sudo tar -zxvf file_name -C /opt
And then to run java use a command like the following:
sudo /opt/jdk1.8.0/bin/java -version
Step 3 – Deploy and Run JavaFX Apps on Your Pi
Almost any JavaFX desktop application will run on the Pi simply by copying over the jar file and executing it locally, with no modifications. (The 2 exceptions to this are applications that rely on WebView or MediaView, both of which are unimplemented in the current dev preview)
A great way to get started building JavaFX applications for the Pi is to use Scene Builder to quickly put together a user interface visually, and then deploy that to the Pi. I did this last night at the Linux Users’ Group of Davis (LUGOD), quickly putting together a sample application with help from the very astute attendees (I also learned a thing or two about linux command tricks along the way from the audience).
I posted our 15 minute application in GitHub as an example you can try:
https://github.com/steveonjava/LUGOD-Pi-Test
To run it on the Pi, build the source with your favorite IDE (or straight form the command line) and build a jar file. Then copy the jar file to your Pi and run it with a command like the following:
sudo /opt/jdk1.8.0/bin/java -Djavafx.platform=eglfb \ -cp /opt/jdk1.8.0/jre/lib/jfxrt.jar:LUGODTest.jar lugodtest.LUGODTest
Here is a picture of the Scene Builder project and the output we got on the Raspberry Pi during the LUGOD meeting:


However, the most impressive demo is your own. Try deploying your own JavaFX applications and leave others pointers to apps you have deployed in the comments below!












Tip: An iPhone charger (the Apple one) works well to supply the power. Just use it with a normal USB printer cable.
Hi Steve, please check your mail (the one in your “contact” section). JavaFX on the Raspberry Pi is excellent!
This is awesome! Tried it today, got it up and running in 30 mins and installed Tomcat 7 and deployed a web application on Raspbian Wheezy System then is at 100% CPU for quite a while but then everything works and the performance is remarkable. Those guys must have done an incredible good job for optimizing the JVM on such a restricted hardware. Very cool!!!
Very very awesome!
Thanks for sharing. I was about to ditch the raspbian wheezy image since it would only support OpenJDK so this makes my night!
You can use an adaptor cable to attach from the HDMI output of the Raspberry to a standard computer monitor. They do not say this on the Raspberry PI web site, but it is in the book (I bought it!). But this will not work on older monitors.
Good point. You can do this if your monitor supports HDMI input. Same caveat about plugging it in before booting so it sees a device hooked up via HDMI, and you may need to fiddle with the display resolution if your monitor does not do a good job reporting its supported formats via EDID. (more details on manual video config here: http://elinux.org/RPiconfig)
i am getting java.lang.UnsatisfiedLinkError: Can’t load library: /opt/jdk1.8.0/jre/lib/arm/libglass.so exception when running my app, full stack trace : https://forums.oracle.com/forums/thread.jspa?threadID=2483988&tstart=0
Did Daniel’s suggestion to set -Djavafx.platform=eglfb work? (this won’t be required in the future, but in the EA is needed right now due to http://javafx-jira.kenai.com/browse/RT-27194)
yes, there is a typo in my command
, i am missing letter ‘m’ in platform . anyway here is my frist JavafX app running on Raspberry pi http://www.youtube.com/watch?v=Rkidpcag1hc
Very cool!
What directory do you need to be in order to run your java code?
mouse does not work?
The mouse works with JavaFX. There are some issues with USB device ordering, so try unplugging other USB devices (or a different mouse if it appears like multiple devices to the OS. For debugging try in xwindows first and read the startup dmsg log.
Hi Steve,
I’m Mathieu, we met at Devoxx France. I ran my first attempt at getting Java FX to display the temperature from an Arduino on the Raspberry Pi, using serial communications directly on the serial port. The hardware part went well, the Pi got the Arduino powered up, and serial port started getting data readings.
On the software end of the problem, I do not know what happened: I tried running my JavaFX application from the jar file. It is pretty basic: I use a serial port callback provided by Pi4J library, and this callback writes data directly to a label. When I run it from command line, it waits a bit, and gives up, without any message.
I will double check my install, I may have missed something (two things come to my head currently: I ran the command from SSH, so the display may be wrong (like missing ‘export DISPLAY’ while doing some X remoting) and I didn’t check my video RAM (might be 16Mb…))
Currently, here is what I have for Arduino plugged to Mac Book using FTDI cable and Processing environment:
https://gist.github.com/mathieubolla/5246609#file-arduinothermosensor
I will keep you informed of the outcome of my tests…
Hi Steve,
I finally got it working. It was the memory split indeed. I had 16Mb, now have 128Mb for video. Plus the library pi4j is not correctly packaged, it has some duplicates in jar files which didn’t pass jar signing process.
Here is my git hub with all required stuff to run my proof of concept: https://github.com/mathieubolla/pihacking
And some pictures to show it working live:
https://twitter.com/mathieubolla/status/319194833476546560/photo/1
Plus a zoom on the ugly UART connection:
https://twitter.com/mathieubolla/status/319195264248340480/photo/1
Thanks again for your inspiring presentation, and for all the JavaFX work on Raspberry Pi. Definitely something to explore again and again…
Cheers, from France.
Mathieu
Awesome! That is a nice project showing serial communication in Java on Raspberry Pi, thanks for sharing the code!
The tutorial is well commented, but what if I whant to run java SDK 1.3.0_02 on a Rasperry Pi Soft-float Debian “wheezy”, have you ever tried to do this, I been working on it and I cant make it work, I made run a newer version but not this one, can you give a little advice please, thank you.
Not sure how much luck you are going to have with something as old as 1.3. If you want to do a soft float build, you can try the Java 7 SE Embedded builds here: http://www.oracle.com/technetwork/java/embedded/downloads/javase/index.html
Remember that these will be headless (no GUI) and you will be taking a performance hit by not using the FPU.