GlassFish Server  is an Open Source provides a server for the development and deployment of Java Platform, Enterprise Edition applications and web based application on Java. his post describes about How to install the GlassFish Server 4.1 and start the server on system.

Requirements:

We need to check some  basic requirements packages have update and installed on your system,              

# yum -y update

Install Oracle JDK 8 :

Two possibilities available to install JDK 8, One is refer the Link and another one is just follow the below steps,

wget --no-cookies  --no-check-certificate  --header "Cookie: oraclelicense=accept-securebackup-cookie"  "http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.rpm"  -O jdk-8u45-linux-x64.rpm
# yum install jdk-8u45-linux-x64.rpm

or
 
# rpm -ivh jdk-8u45-linux-x64.rpm
Preparing...   ################################# [100%]
Updating / installing...
   1:jdk1.8.0_45-2000:1.8.0_45-fcs  ################################# [100%]
Unpacking JAR files...
    rt.jar...
    jsse.jar...
    charsets.jar...
    tools.jar...
    localedata.jar...
    jfxrt.jar...
    plugin.jar...
    javaws.jar...
    deploy.jar...
# java -version

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

 
# whereis java
java: /usr/bin/java /usr/share/man/man1/java.1


Installation :

Create a User glassfish
 
# useradd glassfish

Then, download and  extract the GlassFish 4.1 archive file
 
# cd /home/

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

#  unzip glassfish-4.1.zip
Archive:  glassfish-4.1.zip
   creating: glassfish4/
   creating: glassfish4/bin/
  inflating: glassfish4/bin/asadmin  
  inflating: glassfish4/bin/asadmin.bat  
  inflating: glassfish4/bin/pkg

 
# mv glassfish4 /usr/local/glassfish4

Create a systemd service

To create a new systemd service for GlassFish, choice and use editor vim or vi or any other tool. Copy and paste the below lines.
 
# vim /etc/systemd/system/glassfish4.service
[Unit]
Description = GlassFish Server v4.1
After = syslog.target network.target

[Service]
User=glassfish
ExecStart = /usr/bin/java -jar /usr/local/glassfish4/glassfish/lib/client/appserver-cli.jar start-domain
ExecStop = /usr/bin/java -jar /usr/local/glassfish4/glassfish/lib/client/appserver-cli.jar stop-domain
ExecReload = /usr/bin/java -jar /usr/local/glassfish4/glassfish/lib/client/appserver-cli.jar restart-domain
Type = forking

[Install]
WantedBy = multi-user.target
# systemctl enable glassfish4.service
ln -s '/etc/systemd/system/glassfish4.service' '/etc/systemd/system/multi-user.target.wants/glassfish4.service'


To Start GlassFish :
 
# cd /usr/local/glassfish4/

# ./asadmin start-domain

If you may get an error : remote failure refer the Link,

To Stop GlassFish :
 
./asadmin stop-domain

http://localhost:8080/

http://localhost:4848/