Installing GlassFish on a Raspberry Pi

This post detail how to quickly have GlassFish running on a Raspberry Pi.
As I don’t have a DVI-HDMI adapter, this install will be headless. My Raspberry Pi setup is simple, an ethernet connection with DHCP and power, no screen, no keyboard attached.

Installing the OS

Download from http://www.raspberrypi.org/downloads the Raspbian “wheezy” distribution and dump it to a SD Card. Insert the SD card in the Raspberry, power it. Depending on the SD card performance, the boot process takes between 30 and 60 seconds…

Log in your Raspberry using the default 'pi' user, password: 'raspberry'.
ssh pi@192.168.1.8

Invoke the config tool (sudo raspi-config) and select the expand_rootfs option in order to re-size the disk partition. Just quit the config tool to reboot the Raspberry, or invoke the reboot command, the partition size will be adapted…

Installing Java

Installing the OpenJDK ARM port is easy…

ssh pi@192.168.1.8
sudo apt-get install openjdk-6-jdk

You can use java -version to validate that the JRE is installed and javac -version to test the JDK install.

Installing GlassFish

mkdir /home/pi/soft
cd /home/pi/soft

There are 2 distributions, glassfish-3.1.2.2.zip is the Java EE 6 Full Profile while glassfish-3.1.2.2-web.zip is the Java EE 6 Web Profile. Pick the one you want and download it.

wget http://dlc.sun.com.edgesuite.net/glassfish/3.1.2.2/release/glassfish-3.1.2.2-web.zip

Unzip and start GlassFish…

cd /home/pi
unzip soft/glassfish-3.1.2.2-web.zip
cd glassfish3/bin
./asadmin start-domain domain1

To test your install just curl localhost:8080
You can also drop a simple test/index.jsp in the auto-deploy directory of the installed domain (/home/pi/glassfish3/glassfish/domains/domain1/autodeploy/)

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page - PiTest</title>
    </head>
    <body>
      <h2>PiTest</h2>
        App Server : <%=getServletConfig().getServletContext().getServerInfo()%> <br>
        JVM : <%= System.getProperty("java.version")%> - <%=System.getProperty("java.vendor")%><br>
        Java home : <%= System.getProperty("java.home")%><br>
        OS : <%= System.getProperty("os.name")%> - <%= System.getProperty("os.version")%> <br>
        Architecture : <%= System.getProperty("os.arch")%> <br>
    </body>
</html>