How to Setup GlassFish in Ubuntu

To Setup GlassFish 4.1 in Ubuntu

GlassFish server is a free-ware, light weight application server for the development and deployment of Java Platform and web technologies based on Java technology. It supports
different Java based technologies. Installation of Glassfish in Ubuntu is explained in this manual.

To install dependency

Run the following command to install the dependency packages that are necessary for installing java.

root@linuxhelp:/home/user1# apt-get install python-software-properties 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
.
.
.
Setting up python-apt (1.1.0~beta1build1) ...
Setting up python-pycurl (7.43.0-1ubuntu1) ...
Setting up python-software-properties (0.96.20.4) ...


Add the PPA for installing Java by running the following command.

root@linuxhelp:/home/user1# add-apt-repository ppa:webupd8team/java 
 Oracle Java (JDK) Installer (automatically downloads and installs Oracle JDK7 / JDK8 / JDK9). There are no actual Java files in this PPA.
.
.
.
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK


After adding the PPA repository, use the following command to update the services.

root@linuxhelp:/home/user1# apt-get update 
Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease   
Get:2 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease [17.6 kB]
Hit:3 http://in.archive.ubuntu.com/ubuntu xenial InRelease                           
Hit:4 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease                   
Hit:5 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease     
Get:6 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial/main amd64 Packages [2,840 B]
Get:7 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial/main i386 Packages [2,840 B]
Get:8 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial/main Translation-en [1,260 B]
Fetched 24.5 kB in 1s (16.2 kB/s)
Reading package lists... Done


Run the following command to install the oracle packages.

root@linuxhelp:/home/user1# apt-get install oracle-java8-installer 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
.
.
.
Oracle JDK 8 installed
update-alternatives: using /usr/lib/jvm/java-8-oracle/jre/lib/amd64/libnpjp2.so to provide /usr/lib/mozilla/plugins/libjavaplugin.so (mozilla-javaplugin.so) in auto mode
Oracle JRE 8 browser plugin installed
Setting up gsfonts-x11 (0.24) ...


Once the installation is done, Set the environment variable " JAVA_HOME" as the path of the newly installed Oracle JDK 8. To do so, open and /etc/environment file and add the following lines into it.

root@linuxhelp:/home/user1# nano /etc/environment 
JAVA_HOME=" /usr/lib/jvm/java-8-oracle" 

Save and exit the file.
Then reload the file.

root@linuxhelp:/home/user1# source /etc/environment 


Run the following command to check the java version.

root@linuxhelp:/home/user1# java -version 
java version " 1.8.0_101" 
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

To install GlassFish

First download the glassfish server package and change the directory to temp.

root@linuxhelp:/home/user1# cd /tmp/
root@linuxhelp:/tmp# wget http://download.java.net/glassfish/4.1/release/glassfish-4.1.zip 
--2016-09-17 00:19:29--  http://download.java.net/glassfish/4.1/release/glassfish-4.1.zip
Resolving download.java.net (download.java.net)... 96.17.182.42, 96.17.182.49
&hellip 
&hellip 
2016-09-17 00:25:25 (297 KB/s) - ‘ glassfish-4.1.zip’  saved [107743725/107743725]


Now extract the package into the /opt/ directory by using the following command.

root@linuxhelp:/tmp# unzip glassfish-4.1.zip -d /opt/ 
Archive:  glassfish-4.1.zip
   creating: /opt/glassfish4/
   creating: /opt/glassfish4/bin/
  inflating: /opt/glassfish4/bin/asadmin  
&hellip 
&hellip 
&hellip 
  inflating: /opt/glassfish4/pkg/lib/pkg-bootstub.bat  
  inflating: /opt/glassfish4/pkg/lib/pkg-bootstub.sh  
  inflating: /opt/glassfish4/pkg/lib/pkg-client.jar  


To setup PATH variable for GlassFish, open and edit the " ~/.profile" file as shown below.

root@linuxhelp:/tmp# nano ~/.profile  
export PATH=/opt/glassfish4/bin:$PATH


Reload the file by using the following command.

root@linuxhelp:/tmp# source ~/.profile 

To launch GlassFish

Run the following command to start the GlassFish server.

root@linuxhelp:/tmp# asadmin start-domain 
Waiting for domain1 to start ...................
Successfully started the domain : domain1
domain  Location: /opt/glassfish4/glassfish/domains/domain1
Log File: /opt/glassfish4/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.


Open the browser and point the URL http://< ip-address:8080> / to check the homepage of GlassFish Server


Now to set the password for the application by using the following command.

root@linuxhelp:/tmp# asadmin change-admin-password 
Enter admin user name [default: admin]> admin
Enter the admin password>  
Enter the new admin password>  
Enter the new admin password again>  
Command change-admin-password executed successfully.


To access the administration panel remotely, use the following command.

root@linuxhelp:/tmp# asadmin enable-secure-admin 
Enter admin user name>   admin
Enter admin password for user " admin" >  
You must restart all running servers for the change in secure admin to take effect.
Command enable-secure-admin executed successfully.


After setting the administrative panel, restart the domain.

root@linuxhelp:/tmp# asadmin restart-domain 
Successfully restarted the domain
Command restart-domain executed successfully.


Now open the browser and point to http://ip-address:4848 and enter the user credentials to login remotely.


To deploy an application

To deploy a WAR application into the GlasFish, download hello.war from the glassfsh official page by running the following command.

root@linuxhelp:/tmp# wget https://glassfish.java.net/downloads/quickstart/hello.war 
--2016-09-17 00:36:54--  https://glassfish.java.net/downloads/quickstart/hello.war
Resolving glassfish.java.net (glassfish.java.net)... 137.254.56.48
&hellip 
&hellip 
2016-09-17 00:36:56 (13.7 KB/s) - ‘ hello.war’  saved [4102/4102]


Once the download is completed, deploy it using asadmin command.

root@linuxhelp:/tmp# asadmin deploy hello.war  
Enter admin user name>   admin
Enter admin password for user " admin" >  
Application deployed with name hello.
Command deploy executed successfully.


Open the browser and navigate to http://ip-address:8080/hello

If you are tired of entering the username and password everytime you deploy or undeploy an application, you can simply create a file named pwdfile with a text editor and add the following lines into it.

root@linuxhelp:/tmp# nano pwdfile 
AS_ADMIN_PASSWORD=your_admin_password

Save the file and exit

To undeploy the application

To stop the running application, use the following command.

root@linuxhelp:/tmp# asadmin undeploy hello 
Enter admin user name>   admin
Enter admin password for user " admin" >  
Command undeploy executed successfully.


we can just add --passwordfile flag pointing the pwdfile and then deploy the war application to deploy the application without entering the username and password

root@linuxhelp:/tmp# asadmin --passwordfile pwdfile deploy hello.war 
Application deployed with name hello.
Command deploy executed successfully.
Tag : Glassfish
Comment
dkerrh
May 09 2019
Is there Any Update here to further Glassfish Install, Given that It worked and now we have the return "GlassFish requires Java SE version 6. Your JDK is version 0"
Any Help would be great
Add a comment
FAQ
Q
What platforms does The Java EE 5 Tutorial support?
A
For a list of supported platforms, see the Application Server Release Notes.
Q
Is there any Alternative for Glassfish?
A
Such as,
JBoss,
appserver.io,
Webshare Application Server,
Jonas,
Mako Server
Q
How to start/stop/restart the Glassfish application?
A
Follow the below steps to start/stop the glassfish application.

Step 1: Login to your NGASI panel.

Step 2: Now click the Start/Stop menu in the home page.
Q
Who are the members of the tutorial team?
A
For information about the authors, read Appendix C, "About the Authors".
Q
When Glassfish application should be restarted?
A
When Glassfish application should be restarted? Whenever you deploy your hosting application, you should restart your Glassfish application.