GlassFish is a free open source application server for the Java EE platform. With this application the developers can develop and deploy portable and scalable enterprise Java applications on your Linux VPS.
GlassFish requires a working JDK installation. Skip the first step if you already have it.
1. Install JDK
Create a directory where you want to install JDK:
# mkdir /usr/java
Change to the directory:
# cd /usr/java
Download the latest stable JDK release which currently is JDK 7 update 5 from http://www.oracle.com/technetwork/java/javase/downloads/index.html . Be sure to select the appropriate version to your OS (32 or 64 bit version)
Unpack the downloaded JDK file into the newly created directory:
# tar -xzf jdk-7u5-linux-i586.tar.gz
Set the PATH for the JDK installation by editing your ‘~/.bash_profile’ file and adding the following lines:
export JAVA_HOME=/usr/java/jdk1.7.0_05 export PATH=$JAVA_HOME/bin:$PATH
After setting the PATH variable, execute:
Or you can simply exit and open the command prompt again.
Check if the PATH is set correctly:
# echo $JAVA_HOME
2. Install the GlassFish Server
Change to the directory where you want to install the GlassFish application:
# cd /opt
Download the latest GlassFish zip installation file:
# wget http://download.java.net/glassfish/3.1.2/release/glassfish-3.1.2.zip
Unpack the downloaded zip file:
# unzip glassfish-3.1.2.zip
Usually the zip file is extracted to a directory called ‘/glassfish3’
Since it is not recommended to run the glassfish process as root, we need to add group and user for the GlassFish application:
# groupadd glassfish # useradd -s /bin/bash -g glassfish glassfish # chown -R glassfish: /opt/glassfish3/
Change the password for the ‘glassfish’ user:
# passwd glassfish Changing password for user glassfish. New password:
Create a start/stop/restart script:
# nano /etc/init.d/glassfish
#!/usr/bin/env bash # description: Glassfish start/stop/restart # processname: glassfish # chkconfig: 2445 20 80 JAVA_HOME=/usr/java/jdk1.7.0_05 export JAVA_HOME PATH=$JAVA_HOME/bin:$PATH export PATH GLASSFISH_HOME=/opt/glassfish3/glassfish/ GLASSFISH_USER=glassfish case $1 in start) su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1" ;; stop) su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1" ;; restart) su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1" su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1" ;; esac exit 0
Save the script and make it executable:
# chmod +x /etc/init.d/glassfish
If you want to start up your GlassFish application on boot execute the following commands:
# chkconfig --add glassfish # chkconfig glassfish on
To start/stop/restart Glassfish use the command:
# /etc/init.d/glassfish start/stop/restart
Once the installation is completed, you can open the default GlassFish home page at http://domain.com:8080 or the GlassFish admin console at http://domain.com:4848
Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert linux admins to install this for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.