Summer holidays in Australia always has me searching for a new project to keep me from annoying the kids by stealing their Lego. This year I was introduced to the Raspberry Pi and set myself a goal of installing and running ADF Essentials on this miniature computer.
So what's a Raspberry Pi?
The Raspberry Pi
, or Raspi or Pi for short is a credit card sized computer that was designed to teach the "real" basics of computers to kids. The story goes a "bunch of old computer hacks" recognized that kids today are far removed from the electronics side of computing and as a result we're losing kids with an interest in the fundamentals of what makes computing tick. As such the team had a brilliant idea of creating a small and cheap Linux driven computer with the usual standard connectors (HDMI, USBs etc), but also importantly a set of GPIO pins which allow the Pi to connect a traditional old electronics kit to controls LEDs, switches, sensors and more.
The specs of the Model B Raspberry Pi (there's two models, A and B) are deliberately minimal, running on a 700MHZ ARM processor, 512MB RAN (shared with the GPU), and it doesn't even have a harddrive, but rather uses a SD card for storage. The neat part is the base price for the Model B is only US$35!
If you're exceptional underwhelmed by the specs of the Pi, you might not be understanding the point. This isn't meant to be a highpowered Intel quad-duo-core thing, but a small lightweight computer to learn from, or run exactly one task.
Many people have "got it", and as a result the Pi has reportedly seen huge success in just the last year selling over a million
units. The Pi has found itself not only supporting the important role of teaching kids electronics and computer science, but it has also established itself into the hacker space with people declaring successful projects in robotics
, home media centers
, and lighting a humble LED
when you receive an email.
What's this got to do with ADF Essentials?
The Pi is capable of running different Linux distributions, with a Debian distribution known as Raspbian "wheezy". Instantly this peaked my interest, as where Linux goes, a JVM often follows, followed by Java EE servers such as Tomcat, and ha! Doesn't ADF Essentials run on Tomcat?!
So one 38C (100F) summer Perth day while hiding in the airconditioning I set myself a goal of seeing if I could get ADF to run on the Pi. Why? Why not? I knew it wasn't going to run well, a full blown server solution on only 512MB of memory is pushing the limits, but would it actually run at all?
I'm happy to declare with a few hours to spare and a great amount of patience, a world record was declared on 27th January 2013
From here on in I'd like to describe the steps to build the ADF Essentials Pi from scratch, for all those ADF hackers out there ;-)
Base Pi Specs and Basic Setup
For this setup I worked with a Model B Raspberry Pi with 512MB RAM and a 4GB SD card. By chance the Model A
was released today with just 256MB RAM, possibly a challenge too far for ADF Essentials!
The SD card needs to have a preinstalled Linux of which Raspbian "wheezy" is a Debian distro built specifically for the Pi. For purposes of my tests I used the 2012-12-16 wheezy img/zip available via the Raspberry Pi main website
You can purchase the SD card preinstalled or burn your own installation via your PC/Mac onto the card. The Raspberry Pi wiki
has a good set of instructions on how to do this and I used the RPi-sd v1.2 card builder
for the Mac to assist the process. If you happen to take the RPI-sd route ensure that both the .app and .img files are located in a directory without spaces otherwise you'll hit errors.
After the installation of the base SD, I did hit a problem in getting the HDMI output to work. The fix was via my Mac to edit the config.txt
file on the SD card to include the following line
Upon the first boot of the Pi you're presented with the Raspi-config
screen, of which I changed the following options:
- expand_rootfs - invoked
- change_locale - selected an Aussie locale en_AU.UTF-8
- change_timezone - Australia/Perth
- ssh - enabled
- boot_behaviour - Start desktop
There is also an update command. As I live behind the Oracle proxy this didn't work for me, but it's worthwhile to run if you've a normal internet connection to update your Pi with the latest software.
Once rebooted you're greeted with the Raspberry Pi desktop:
Due to the proxy issue above, I opened a terminal, configured apt-get to work with the Oracle proxy:
sudo nano /etc/apt/apt.conf.d/01proxy
..with the following line:
..and on returning to the terminal executed the following 2 lines to update my Pi installation with the latest software:
sudo apt-get update
sudo apt-get upgrade
This will take sometime to complete, time for a nice cup of raspberry tea while you wait.
As connecting the Pi to a dedicated monitor becomes a bit tedious, you can configure SSH and a VNC server so you can maintain the Pi remotely. Firstly you'll need to know the IP address of the Pi through executing ifconfig
in the terminal so you can connect via SSH/VNC. Remember that by default the Pi uses dynamic IP (DHCP) so this may change on each boot. I'll assume 10.1.1.2 from here on in.
To use and setup SSH
and a VNC server
, Adafruit provides good instructions on how to do this. Ensure to remember the password you define for the VNC server.
From a Mac accessing the Pi via SSH is easy as it's supported through the terminal/Mac OSX. On Windows you'll need to install a dedicated SSH client.
Also from a Mac accessing the Pi via a VNC client is easy as it comes with a ready made VNC client "Screen Sharing.app" located under /System/Library/CoreServices in OSX Mountain Lion. Remember the user id/password combo is that you specified when setting up the VNC server, and the password is a maximum 8 characters long.
On accessing the Pi you'll need to enter the IP address you discovered before and the port number. Note if you started the VNC server on the Pi using something like "vncserver :1", the port number you must access is 590 + the digit you started the vncserver, 1 in this example, along the lines of 10.1.1.2:5901.
On accessing the Pi from VNC for the first time I did hit the following error:
"GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: An authentication agent already exists for the given subject"
..and a fix is suggested here
It's also worthwhile installing the Chromium
browser and an FTP server such as proftpd
Setting up the ADF Environment
Once we have the basic Pi up and running, we're now ready to install the infrastructure and software required for ADF Essentials. In brief this includes:
- JDK 1.6 SE
- Apache Tomcat 7
- jsf-api.jar + jsf-impl.jar + glassfish.jstl_184.108.40.206.jar
- Oracle ADF Essentials
- Oracle ADF Component Demo
The following instructions are mostly derived from Raphael Rodrigues's blog
with a couple of twists.
At the time of writing this article there was some "hoohaw" over Java security and a rapid release of JDKs from Oracle to patch security holes. As such an ARM distribution from Oracle of the JDK wasn't yet available. To give myself the chance of finishing this blog post I went with installing the OpenJDK. Warning: I've no idea if the current distribution includes all the security patches necessary. However somehow I don't think security is a primary concern for most Pi uses:
sudo apt-get install openjdk-6-jdk
Tomcat is also a fairly painless task. First visit the Tomcat 7 download
page and determine which is the latest version. At the time of writing this was 7.0.35 for me. In addition locate the tar.gz link and note the URL. This will automatically be pointing at a mirror close to your location.
Return to the Pi terminal, ensure you're in the home directory and execute the following command, but change the URL to suit the one presented in the previous step:
Once downloaded, execute the following command to explode the tar to your home directory:
tar zxf apache-7.0.35.tar.gz
You can then start and stop the tomcat server by executing one of the following 2 commands after issuing the cd command:
sudo sh startup.sh
sudo sh shutdown.sh
Via the Pi desktop if you open the Chromium browser, you should be able to access the Tomcat console by going to http://localhost:8080, or remotely via the ip address such as http://10.1.1.2:8080. Be patient for the server to start.
At this point shutdown the Tomcat server.
Next we need to install the jsf-api.jar, jsf-impl.jar and glassfish.jstl_220.127.116.11 jar files into the TOMCAT_HOME/lib directory. These are best borrowed from an existing JDev 18.104.22.168.0 installation on your local PC/Mac and ftp'ed across from JDEV_HOME/oracle_common/modules/oracle.jsf_2.0
Finally we're ready for some ADF setup!
We need to install the ADF Essentials runtime libraries into Tomcat. Officially Oracle doesn't support Tomcat (at least currently) against ADF Essentials, but this doesn't mean ADF doesn't run on Tomcat.
As ADF Essentials requires you accept the license conditions on Oracle's website before you download it, you cannot use wget to do this. In addition attempting to download this via the Chromium browser isn't that easy as it's chews so much CPU that often it times-out before it has a chance to download any file. As such the easiest solution seems to be to download
the 22.214.171.124.0 ADF Essentials file on your PC/Mac and then ftp it across to your Pi. While you're at the same site, also download the Oracle ADF Faces Components Demo 126.96.36.199.
Move the ADF Essentials zip file to the TOMCAT_HOME/lib, and extract it using the following command:
unzip -j adf-essentials.zip
The -j option here flattens the directory structure within the zip such that all JARs included are placed in the Tomcat lib directory directly, not a subdirectory there of.
The final part of the install is we need to deploy the ADF Component Demo. There is a number of different deployments options to take, but the easiest is to place the associated .war file in the TOMCAT_HOME/webapps directory. However the file is a rather large and chunky application of over 100MB of source code. Tomcat's default behavior at runtime is to explode the war into a directory of the same name at startup, and given the resources of Pi this is going to take a long time.
Best solution is to preexplode the file for Tomcat, by making a directory, say TOMCAT_HOME/webapps/rcf-dvt-demo, copy the war into this new directory and execute unzip on the zip file. Remember to delete the zip file once done.
One last fix. From experimentation Tomcat 7 on starting will attempt to scan all the source code for annotations to execute. To stop it doing this we can modify
the WEB-INF/web.xml file of the demo we just exploded, and add the attribute metadata-complete="true" to the <web-app> node. As you're about to see starting the Tomcat server with all the preconfigured ADF software is a *really* long process.
Drum Roll: Voila! ADF Essentials on the Raspberry Pi
So the big drum roll moment is to again start Tomcat and then access the application via a browser. Just starting the Tomcat server is now going to consume a vast amount of CPU. In fact 2984981 ms at 100% CPU on my Pi! Phew.
What you can do while the server starts up is execute "tail -f" on the catalina.log file found under the TOMCAT_HOME/logs. Very very slowly you'll see the server start up. You might note the server seems to start 1 or two apps that aren't possibly needed and this could be something we could eliminate to speed the startup process later.
Finally once up and running, open the browser and access http://10.1.1.2:8080/rcf-dvt-home/faces/index.jspx. Once again it will take sometime to start and load, but eventually you'll see the component demo running. If you attempt to open another session to the same page (say from your PC/Mac) you will see it's an order of magnitude faster. But it does run!
"But Chris, it runs so slowly it's near useless!"
Ya, I did set expectations early on that it would run slowly, and you weren't seriously going to run an enterprise framework on a Raspberry Pi were you? The goal here has been to see if it will just run, and it does.
"But Chris, what about ADF BC/EJB/my favorite part of ADF?"
Indeed, I didn't make any claims of exercising the entire ADF stack. Though it would be fun to try. The component demo is a good exercise in that it's a very large JSF application. I'd love to see somebody try to get ADF BC running by seriously throttling back the AM and connection pool. Could you even install MySQL on the same Pi to be fully contained? Hmmm, sounds like a cool hacking opportunity!
"But Chris, did you try X/Y/Z to speed up deployment?"
Awesome, you've got some hacking ideas! Let's start an ADF Pi community and take this further for the fun of it :-)
In summary the Raspberry Pi provides an awesome learning environment for kids to learn about computer science, but also a great playground for old fellas like me to see if we can get our favourite technologies to work on this mini computer. I look forward to reading your Raspberry Pi ADF stories soon.