Tuesday, July 03, 2012

Java on the Raspberry Pi

As anybody familiar with my blog will no doubt be aware, I'm a Java programmer by day, and one of my ideas for using my Pi is as a little web-server. I fancy having a go at writing one for myself, just to see what the fuss is all about ;-) So, Java is the logical choice for me! (At which point, any number of language nerdsgurus will insist that I'm made, and that I should do it in C/C++/C11/Fortran/Python/Bash ... you name it, anything but 'slow' Java)

Anyhow. Space is at a premium on the Pi, so I thought I'd try installing a JVM/JDK on my CIFS mounted file-system that actually lives on my desktop PC. Unfortunately, that filesystem is NTFS (underneath the hood), and that means it doesn't support Unix-style soft links... and the JDK that is available for the Pi (OpenJDK) is full of them, even once you get through the layers of soft links around the file system that lead to /usr/lib/jvm/java-6-openjdk. So, the network mount was out of the question. (Maybe someone, somewhere, has instructions for creating a virtual file system in a file on a network share, where the filesystem inside is something more native to Debian Squeeze Linux).

The not so bad news is that OpenJDK 6 is actually only (only?) 108Mbytes, which I can afford as long as I keep my project code on my projects drive. So, assuming your system is setup as I've described in previous posts:

  1. SSH/VNC to the Pi, logging in as 'pi'
  2. Run "ln -s /mnt/projects" to create a projects folder in my home directory that's actually safely squirrelled away on my PC. (auto-magically double backed-up every night via SyncToy and DropBox, by the way)
  3. Now install the OpenJDK version 6 (I'll save JDK 7 for another time as that's a whole different kettle of rather narsty fish!): run "sudo apt-get install openjdk-6-jdk"
  4. It takes a while, but when it's done, "which java" should give you:
    pi@raspberrypi:/$ which java
  5. and "java -version" should give:
    pi@raspberrypi:/$ java -version
    java version "1.6.0_18"
    OpenJDK Runtime Environment (IcedTea6 1.8.13) (6b18-1.8.13-0+squeeze1)
    OpenJDK Zero VM (build 14.0-b16, mixed mode)
  6. Now run "sudo apt-get clean", to remove the cached installation files from the various tools you've installed - I found this saved about 50Mbytes of space, so a not inconsiderable saving on such a small file system.
  7. Now to write some Java code.

Raspberry Pi Power Supply

One of the features of the Pi is that it comes with nothing in the box other than the bare board. No power supply, no SD card, no no network cable, no nothin'. 

On the basic setup Pi forums there are a number of topics on the subject of what power supply to use. Well, I don't know about anybody else, but I found that the power supply that comes with an Amazon Kindle was just perfect. 

The specification and FAQ on the Model B Pi board (the one that is available just now) is that it requires a stable 5V supply of at least 0.7Amps. The Kindle charger is rated at 5V at 0.85A ... match. Of course, it's all very well having a charger with the right rating, but I suspect more people will struggle with the power connector - it's a micro-USB. Yes, 'micro'. Not a mini-USB like a Sony eReader, or my old Motorola phone, and not the weird slim, wide, pseudo USB that my newer Samsung phone uses. It's a about the same width as the mini-USB, but half the thickness. In the FAQ, the Raspberry Foundation claim that GSMA expect micro-USB will be the universal charging solution for mobile devices, but it's not there yet.

So, as I say, the Kindle charger works just fine, which is just as well because despite quite a collection of mobile phone chargers and other electronic devices connectors, the Kindle charger is the only one that works for me.