How to setup Glassfish on ubuntu

glassfish logo

NOTE: It has come to my attention that this starts glassfish with root privileges which wouldn’t be good if this wasn’t a test server! A alternative (and better method) can be found at link cheers Jasper.

First you need to download the installer file from the glassfish website
Download

which was glassfish-installer-v2-b58g.jar

Next you need to decide where you want to install it… For example /usr/local/appname. So you will need to copy the install.jar to /usr/local (the jar will extract files into a glassfish folder).

Next you follow the steps on the web page above… so basically…

sudo -s
ENTER PASSWORD (Root Password)
java -Xmx256m -jar glassfish-installer-v2-b58g.jar
cd glassfish
chmod -R +x lib/ant/bin
lib/ant/bin/ant -f setup.xml

Next you can either start it with the command
/usr/local/glassfish/bin/asadmin start-domain domain1

Or better create a init.d file to start and stop it…

gedit /etc/init.d/glassfish

GLASSFISHPATH=/usr/local/glassfish/bin
case ”$1” in
start)
${GLASSFISHPATH}/asadmin start-domain domain1
;;
stop)
${GLASSFISHPATH}/asadmin stop-domain domain1
;;
restart)
${GLASSFISHPATH}/asadmin stop-domain domain1
${GLASSFISHPATH}/asadmin start-domain domain1
;;
*)
echo $”usage: $0 {start|stop|restart}”
exit 1
esac

save and exit

chmod a+x /etc/init.d/glassfish

to have glassfish start during boot (and stop during halt)

ln -s /etc/init.d/glassfish /etc/rc1.d/K99glassfish
ln -s /etc/init.d/glassfish /etc/rc2.d/S99glassfish

Voila that’s it…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s