Get up and running with GroovyFX on the Raspberry Pi

This Christmas, I received a Raspberry Pi from Santa, so thought I’d have a go at getting JavaFX running on it. Of course, due to my interest in all things Groovy, I decided to go straight for getting GroovyFX running. After a day or two of foozling around (and at least half a day getting distracted by the RASPBMC media centre), I succeeded so thought I would post the steps I took here so others can follow my path to GroovyFX happiness.

Writing an image to SD card

First off when you get your Pi, you need to prepare an SD card with an OS. I chose Raspbian “wheezy” as it’s the one recommended for beginners, and it’s based on the Raspbian optimised version of Debian, and containing LXDE, Midori, development tools and example source code for multimedia functions.

So, download the image from the Raspberry Pi downloads page, unzip it and write it to your SD card — instructions are on that page, but I am on OS X and chose to use the RPi-SD card builder so there was less chance of me messing something up using the dd command ;-)

Once that’s done, take the card out of your machine, put it into your Pi, plug it all in and switch on!

A bit of setup

Once your Pi boots, you’ll be greeted with this:


The first thing to do is expand_rootfs. This allows you to use all of your SD card space (the image you wrote to it only opens up a small portion of the available room)

Then, select memory_split and give the GPU 128MB of memory to play with (as we’re going to be messing with graphics).

Change your password if you want (the default is raspberry), and I ran update to make sure everything was nice and up to date.

I also ran overclock. By slowly going up one step at a time, I found I could run in high setting, but turbo caused my SD card to not load properly — if this happens to you, hold SHIFT while booting, then run sudo raspi-config and set it back to the highest successful level

If ever you find yourself needing to go back to this menu at a later date, just type sudo raspi-config.

Now the last step for the setup, when you have rebooted and logged in, edit the file /boot/config.txt and uncomment the two lines:

This will force a 720p resolution, so will make the pixel count less when we start throwing stuff to the screen.

Then, reboot with sudo shutdown -r now and we’re on to the next step… JAVA!

Installing Java

In late 2012, Oracle released the JDK 8 (with JavaFX) for ARM Early Access. So download the gzipped tar file from there, scp it across to your pi (or just download it via the midori browser found when you run startx to get the windowing system up), unpack it then copy the jdk1.8.0 folder somewhere sensible:

Then, edit ~/.bashrc and add the lines:

Now, enter source ~/.bashrc to load your changes and then typing java -version should present you with something like:

java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b36e)
Java HotSpot(TM) Client VM (build 25.0-b04, mixed mode)

Installing Groovy

For installing Groovy, I decided to give GVM a whirl as it seemed like (and indeed was) the simplest route to take. Simply type:

curl -s | bash

Follow the on-screen instructions (there’s only one — to reboot or source a file), and then type:

gvm install groovy

That’s it.  Groovy 2.0.6 is now installed… Don’t believe me? Type groovy -version and you should see:

Groovy Version: 2.0.6 JVM: 1.8.0-ea Vendor: Oracle Corporation OS: Linux

Grabbing the GroovyFX repo

GroovyFX is hosted on Github so to grab the source, we’re going to need to install git on our Pi. This is easy, just type apt-get install git-core and wait for it to finish.

Then, we can fetch our repo.

For the Pi, I needed to make 2 changes to the source code.

The first (shown here) to src/main/groovy/groovyx/javafx/GroovyFXEnhancer.groovy is that the JavaFX WebEngine class seems to fail to load as it cannot find any resources files available (I tried 2 locales, en_US and en_GB, both failed and I gave up)

The second (shown here) is that we are using a different version of JavaFX so need to change the file accordingly

Building GroovyFX on the Pi

All set, we can now just type:

At this point, you might want to go and get some lunch, phone some friends or do something else time consuming as this takes about 15-20 mins from cold to build. Unfortunately running the Gradle daemon doesn’t help as the buildSrc in the groovyfx project does something funky to the paths to get the demos to run from gradle.

Our test script

So, going for the simplest example script, we have the following:

Which as you can see is the stock HelloGroovyFX example but with the width and height changed to match our Pis output, and a KeyPress handler so we can quit it

Running the test

And then we come to the final step, running the script. We need to set our classpath and tell javafx that we are using the eglfb profile, but that’s simple too. Just run:

and you should see (after a bit of a startup wait) the GroovyFX text appear on your screen!


Hope this helps someone get started with GroovyFX on the Raspberry Pi!


Blog comments powered by Disqus