C2B2 logo icon

A Smartphone as a JEE Server: Glassfish 4 on Ubuntu Touch


Last year, following the release of the much anticipatedRaspberry Pi, Steve couldn’t resist getting JBoss EAP 6 to run on it, which hemanaged with minimal effort! Not to be outdone, I’ve been inspired by the recent releaseof Ubuntu Touch – Canonical’s offering for mobile devices. Mark Shuttleworth’s trailervideos for the upcoming OS gave me a lot to be excited about; I’ve longbeen wondering what could be possible if only I could unlock the power of thecomputer I have in my pocket. Android is (at the moment) my favourite mobile OS, but it’salways disappointed me a little that there was no way to get Java running on itsince it lacksnecessary packages so when Ubuntu Touch was announced, it finally seemedthat there was a New Hope!

How is it done?

Surprisingly easily, once you know the correct steps.
InstallingUbuntu on the Galaxy Nexus is as easy as a single command, provided you’vealready unlocked the bootloader. The installation process took a while – around30 minutes I think. In any case, it was far too long for a keen early adopterto just sit around waiting! To fill my time, I downloaded the latest Java SEembedded from Oracle (a painful mistake) and the latest promoted build ofGlassfish 4. (If you’re going to be an early adopter, you may as well do itright.)
Ubuntu installs itself very differently to how I expectedand, being unfamiliar with Android administration, there was a bit of alearning curve! Using the Ubuntu SDK’s QT creator IDE, you can easily start anSSH session to your phone, once you have wifi configured. I expected theterminal to be limited to some degree, but what I didn’t expect was for it tolie to me!
After connecting, a quick pwd tells me I’m in the/home/phablet directory (phablet being the default user in Ubuntu Touch). The “phablet”user has limited permissions and I quickly found I was unable to switch to theroot user. I’m an impatient man at the best of times, so rather than try tospend time fixing that, I simply used the Android Developer Bridge (adb) thatQT uses to connect to the device. A couple of further pwds in variousdirectories told me that Ubuntu actually creates /data/ubuntu and uses thatdirectory as root, so although the “phablet” user couldn’t see outside of it tothe Android files, the root ADB user could!

Installing Java

Installing Java was not a fun task. I tried various ways oftransferring the downloaded file over to the phone using any method I couldthink of which would work on a full terminal. Finally, I resorted to ADB oncemore, usingthe push command. I then quickly found out that the terminal was powered byBusyBox and it simply refused to run certain packages. (At this point, Isuspected a full conspiracy towards my failure by my phone and Ubuntu desktop.)
I am nothing if not stubborn, however, and, remembering thatOpenJDK 7 is certified for ARM chipsets, I just tried to run apt-get on theright package from QT which, to my surprise, worked first time!
phablet@localhost:~$ java-version
java -version
java version"1.7.0_07"
OpenJDK Runtime Environment(IcedTea7 2.3.2) (7u7-2.3.2a-1ubuntu1)
OpenJDK Zero VM (build22.0-b10, mixed mode)

Installing Glassfish 4

I wasn’t expecting much success after the trials of gettingJava to run in an environment that was so foreign to me, but I had a go anyway.After getting thelatest promoted build of Glassfish 4 from the Aquarium, I pushed the .zipover to the device with ADB again. After unzipping, I tried to start thedomain: bin/asadmin start-domain domain1
BusyBox refused to execute asadmin (I ran chmod 755 just tobe sure). Since I’d spent the best part of the afternoon on trying to get this towork, in desperation, I thought I would move the installation directory to/home/phablet and try to run the command over SSH, rather than as root overADB.
I ran the same command and, to my surprise, Glassfishstarted to load. Surprise quickly turned to horror when I realised that I wasrunning full Glassfish on full Java 7 without changing any heap settings!
After about 2 minutes of waiting with bated breath, thecommand returned that it had started successfully. I could hardly believe it,so I went to the admin console to check:
Not bad for an afternoon’s work! Now all that’s left is toconfigure it!
All in all, Ubuntu Touch is certainly not ready for thepublic, but I’m very impressed with Unity as a smartphone interface and thepower of having a full linux distribution in your pocket.