Monday Apr 30, 2012

JavaFX on the Raspberry Pi

Over the last few days I've been playing with the Raspberry Pi board (I was lucky enough to secure one of these as part of the work Oracle is doing to ensure that Java runs smoothly on it). 

Initial setup was pretty straightforward although I did need to check the current rating of the power supply I was using as the board needs 700mA, which is more than a normal USB port or hub supplies.  I used Win32DiskManager to copy the OS image to an SD card and then gparted to resize the partition to use the whole 8Gb on the card rather than just 2Gb.  Since I don't have a spare monitor I decided to do most things remotely over the network and set up sshd without any problem.

There is an OpenJDK build for ARM, but it doesn't have JIT support, so performance is not optimal.  Oracle provides a commercial implementation, which does have JIT support, so I downloaded and installed this which was painless. (The only thing to note here is I used the vfp version of the JDK).

Next, I figured I'd have a go at building JavaFX from source.  I grabbed a snapshot and set about seeing what needed to be done.  The first problem was that the reported platform didn't match anything in the build description (ARM v. x86).  Being a bit lazy I cheated.  Rather than configuring a whole new set of build rules I just overrode the architecture setting and forced it to i586.  Since the compiler is ARM, what's the worst that could happen?  This got me started, but then I bumped in to issues with some of the native media code compiling with SSE2 optimisations that don't exist on ARM.  A short learning curve later I switched to the ARM NEON equivalent, changed some definitions and got a bit further.  There were a few more issues around missing packages and left over .o files and then a stroke of real luck. 

Someone in Oracle contacted me to say that we already had an internal build of JavaFX for ARM which had been done for the Beagle Board and pointed me to where I could download it, which I duly did.  I copied over all the necessary bits as well as one of my own, simple JavaFX apps compiled into a jar.  After a few command line mis-starts I had JavaFX up and running on the Raspberry Pi!

Here's a quick video that shows the results:

At the moment this is as far as I've got.  I did try a more complex application, but ran into a problem with a missing library.  Something to track down later.

Getting the remote desktop working was a bit of a challenge, but not because of anything to do with the Raspberry Pi or Java.  Initially I thought I could use ssh -X and then project the X application (JavaFX) back to my Mac so I could do the screen capture.  Although this worked fine if the client machine was Linux every time I tried it on Mac OS X I got an access error for MIT-SHM.  It seemed the X environment was trying to use shared memory, which when the client and server are on different machines is not going to work.  I tried several ways to try and convince the system not to use the shared memory extensions, but it just wasn't happening.  In the end I gave up and decided that the path of least resistance was to use VNC and have the whole desktop visible on the Mac.

Stay tuned for more updates.


A blog covering aspects of Java SE, JavaFX and embedded Java that I find fun and interesting and want to share with other developers. As part of the Developer Outreach team at Oracle I write a lot of demo code and I use this blog to highlight useful tips and techniques I learn along the way.


« February 2015