About Glassfish

Glassfish is an opensource application server for Java Enterprise Edition. Its latest version, GlassFish 4.0, supports JavaServer Pages, servlets , RMI, JMS, JavaServer Faces, JPA, Enterprise JavaBeans. With it developers can build and deploy scalable and portable enterprise java applications on a server on LinuxBlock.

Here we will go through, how to set up Glassfish on CentOS 6.

'

Step 1: Setting up the JDK

To get up and running, You will need a working JDK, neglect this is you already have one :

 # mkdir /usr/java  

Enter the directory

 # cd /usr/java  

Browse the Oracle technetwork and download the latest stable JDK. The latest stable one being JDK 8. Ensure you choose the right version for your Linux OS (32 or 64 bit). https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Untar the downloaded JDK within the newly created directory.

 # tar jdk-8u201-linux-x64.tar.gz 

Edit the '~/.bash_profile' file, to set the JDK path. By adding the following lines:

export JAVA_HOME=/usr/java/jdk1.8.0_161
export PATH=$JAVA_HOME/bin:$PATH

Once this is set, run the command

 # .bash_profile 

Echo the JAVA HOME to see if the path is set correctly.

 # echo $JAVA_HOME 

Step 2: Install the GlassFish Server

Switch to a directory where you want to install the GlassFish application:

 # cd /opt 

Download zip file for installation

 # wget http://download.java.net/glassfish/3.1.2/release/glassfish-3.1.2.zip 

Switch to a directory where you want to install the GlassFish application:

 # cd /opt 

Download zip file for installation

 # wget http://download.java.net/glassfish/3.1.2/release/glassfish-3.1.2.zip 

Unzip the downloaded archive file

 # unzip glassfish-3.1.2.zip  

The archive is unpacked into a directory called glassfish3

Next, we add a group with its own user, for the glassfish application because its not recommended to run glassfish as root.

# groupadd glassfish
# useradd -s /bin/bash -g glassfish glassfish
# chown -R glassfish: /opt/glassfish3/

Change the password for the new glassfish user

# passwd glassfish
Changing password for user glassfish.
New password:

Create a start/stop/restart shell script for glassfish

 # vi /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 add executability to it.

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

To add on boot startup features to glassfish. Fire up the following commands:


# chkconfig --add glassfish
# chkconfig glassfish on

For start/stop/restart functionality in Glassfish use the command:

 # /etc/init.d/glassfish start/stop/restart  

Once completed, you can launch a browser and open the default GlassFish home page at http://domain.com:8080 or the GlassFish admin console at http://domain.com:4848

Phanerus Banner