User Tools

Site Tools


Installing GlassFish V3 Final on Ubuntu

I setup a new server and wanted to run Glassfish on it. V3 had just become FINAL but it wasn't in the Ubuntu repository so I decided to do things myself.

Step 1: Setting up Java

The OpenJDK was installed on my machine by default. I'm not sure if the Open JDK is “certified” and I'd rather not go through the frustration of finding out. So I decided to uninstall it and use Sun's JDK.

sudo apt-get remove openjdk-6-jre openjdk-6-jdk
sudo apt-get install sun-java6-jdk  sun-java6-jre
sudo apt-get autoremove

There were several dependent packages I had to confirm on both the remove and the install. And I ran the autoremove command to get rid of several automatically-installed packages that weren't needed anymore, like ca-certificates-java and libjline-java. Again, I don't know what those are for, but they aren't required for the Sun JDK.

I confirmed that I had the desired JDK by looking in the /etc/alternatives/ directory:

me@myhost:~$cd /etc/alternatives
me@myhost:/etc/alternatives$ ls -lrt java*
lrwxrwxrwx 1 root root 39 2009-11-01 18:02 java_vm -> /usr/lib/jvm/java-6-sun/jre/bin/java_vm
lrwxrwxrwx 1 root root 40 2009-11-01 18:02 java-rmi.cgi -> /usr/lib/jvm/java-6-sun/bin/java-rmi.cgi
lrwxrwxrwx 1 root root 43 2010-02-05 14:53 javap.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/javap.1.gz
lrwxrwxrwx 1 root root 33 2010-02-05 14:53 javap -> /usr/lib/jvm/java-6-sun/bin/javap
lrwxrwxrwx 1 root root 43 2010-02-05 14:53 javah.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/javah.1.gz
lrwxrwxrwx 1 root root 33 2010-02-05 14:53 javah -> /usr/lib/jvm/java-6-sun/bin/javah
lrwxrwxrwx 1 root root 45 2010-02-05 14:53 javadoc.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/javadoc.1.gz
lrwxrwxrwx 1 root root 35 2010-02-05 14:53 javadoc -> /usr/lib/jvm/java-6-sun/bin/javadoc
lrwxrwxrwx 1 root root 43 2010-02-05 14:53 javac.1.gz -> /usr/lib/jvm/java-6-sun/man/man1/javac.1.gz
lrwxrwxrwx 1 root root 33 2010-02-05 14:53 javac -> /usr/lib/jvm/java-6-sun/bin/javac
lrwxrwxrwx 1 root root 48 2010-02-05 14:56 javaws.1.gz -> /usr/lib/jvm/java-6-sun/jre/man/man1/javaws.1.gz
lrwxrwxrwx 1 root root 38 2010-02-05 14:56 javaws -> /usr/lib/jvm/java-6-sun/jre/bin/javaws
lrwxrwxrwx 1 root root 46 2010-02-05 14:56 java.1.gz -> /usr/lib/jvm/java-6-sun/jre/man/man1/java.1.gz
lrwxrwxrwx 1 root root 36 2010-02-05 14:56 java -> /usr/lib/jvm/java-6-sun/jre/bin/java

See all the references to the java-6-sun folder? That's a good thing. It means all the tools are pointing to the right place.

Step 2: Installing Glasfish

Since I'm working on my Linux box remotely through an SSH window, I decided to download the platform-independent archive. There are 2 profiles you can choose from: enterprise and web. The enterprise profile is ~18MB larger, but that only takes a few more seconds on a good connection. :-) Besides, that's what I'll be working with. (Don't worry–you can switch profiles easily after the install). There's also a Glassfish V3 self-extracting installer if you like to have your hand held.


This left me with a glassfishv3 folder in my home directory. At this point, I began to think about the proper location for the software (/var vs /opt), security , file permissions, etc. So I browsed the web and found an article from a guy named Stein Kåre Skytteren who has already done this. The next bits here come from his blog entry: (Thanks, Stein!)

sudo useradd --system glassfish -d /opt/glassfishv3
sudo chgrp -R admin /opt/glassfishv3
sudo chown -R glassfish /opt/glassfishv3
sudo chmod -R +x /opt/glassfish/bin/
sudo chmod -R +x /opt/glassfish/glassfish/bin/

These commands create a user called 'glassfishv3'; change the file owner:group to glassfish:admin; and mark the files in the two bin folders as executable. Next we create an init script in the /etc/init.d/ folder

sudo vi /etc/init.d/glassfish
(paste the lines below into the file and save it...)

#! /bin/sh

case "$1" in
echo "starting glassfish from $GLASSFISHPATH"
sudo -u glassfish $GLASSFISHPATH/asadmin start-domain domain1
$0 stop
$0 start
echo "stopping glassfish from $GLASSFISHPATH"
sudo -u glassfish $GLASSFISHPATH/asadmin stop-domain domain1
echo $"usage: $0 {start|stop|restart}"
exit 3

And finally we add the /etc/init.d/glassfish init script to the default runlevels, and start it:

sudo chmod a+x /etc/init.d/glassfish
sudo update-rc.d glassfish defaults
sudo /etc/init.d/glassfish start

And now we have a running glassfish!

/home/cfreyer/public_html/data/pages/technology/java/installing_glassfishv3_on_ubuntu_9.10.txt · Last modified: 2010/02/05 16:28 by Chris Freyer