There are many tutorials available to help you install OpenJDK and JBoss. This is one on the latest concerning Oracle Java and Glassfish. Hopefully this will make deploying easier for Java EE developers.

You will need a server with Ubuntu 12.04.3 x64 that has been created with DigitalOcean. Login as root by ssh. This article assumes no Java installed and at least 1G memory, as Java EE servers are quite demanding.

What is Glassfish?

GlassFish is an open-source application server and the reference implementation of Java EE. GlassFish 4.0 release supports the latest Java Platform: Enterprise Edition 7. It supports Enterprise JavaBeans, JPA, JavaServer Faces, JMS, RMI, JavaServer Pages, servlets, etc.

Step One: Install Oracle Java 7

Start by updating the package index:

sudo apt-get update

In order to get Oracle Installer of Java 7, we need to add a new apt repository. In order to use add-apt-repository, you need to install python-software-properties. Here’s how to do it by apt-get:

sudo apt-get install python-software-properties

Now you can add the new repository and install from Oracle Installer:

sudo add-apt-repository ppa:webupd8team/java

Make source list up-to-date:

sudo apt-get update

Install Java 7 by apt-get:

sudo apt-get install oracle-java7-installer

After installing, confirm the current Java is Oracle version:

java -version

You will see this:

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

Step Two: Install Glassfish 4.0

Get Glassfish Zip file


Install unzip first before unpackage to /opt

apt-get install unzip

Create the directory /opt and then unzip the package to /opt:

unzip -d /opt

For convenience, add export PATH=/opt/glassfish4/bin:$PATH to the end of ~/.profile.

Start the glassfish server:

asadmin start-domain

You will see:

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.

A domain is a set of one or more GlassFish Server instances managed by one administration server. Default GlassFish Server’s port number: 8080. Default administration server’s port number: 4848. Administration user name: admin; password: none.

In order to visit admin page (yourserverid:4848) remotely, you need to enable secure admin:

asadmin enable-secure-admin

You will see:

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.

Restart domain to make effect of secure admin:

asadmin restart-domain

You will see:

Successfully restarted the domain
Command restart-domain executed successfully.

Now you can visit admin page (yourserverid:4848) in browser

To stop the GlassFish server:

asadmin stop-domain

You will see:

Waiting for the domain to stop .
Command stop-domain executed successfully.

Demo service: deploy hello.war on Glassfish

Download the sample application from Glassfish official samples:


Deploy war file:

asadmin deploy /home/ee/glassfish/sample/hello.war

You will see:

Enter admin user name>  admin
Enter admin password for user "admin"> 
Application deployed with name hello.
Command deploy executed successfully.

Now you can visit yourserverid:8080/hello

To undeploy the application:

asadmin undeploy hello

You will see:

Enter admin user name>  admin
Enter admin password for user "admin"> 
Command undeploy executed successfully.

In order to save typing “admin user name” and “password” every time you deploy or undeploy an application, create a password file pwdfile with content:


Add –passwordfile in command:

asadmin --passwordfile pwdfile deploy /home/ee/glassfish/sample/hello.war

Now the prompt for user name/password won’t appear.

By Adarsh Vengarathodi

Hey there! I'm the founder and the CEO of MistLayer, Inc. In this role, I oversee the company’s overall product direction and development and leads the engineering, product and infrastructure teams. I have more than 12 years of software, systems and product development experience, including hardware and software engineering, product management, quality assurance and support.