This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:
Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.
See Instead: This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.
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 droplet 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.
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)
Get Glassfish Zip file
wget download.java.net/glassfish/4.0/release/glassfish-4.0.zip
Install unzip first before unpackage to /opt
apt-get install unzip
Create the directory /opt and then unzip the package to /opt:
unzip glassfish-4.0.zip -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 (your_server_id: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 (your_server_id: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.
Download the sample application from Glassfish official samples:
wget https://glassfish.java.net/downloads/quickstart/hello.war
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 your_server_id: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:
AS_ADMIN_PASSWORD=your_admin_password
Add --passwordfile in command:
asadmin --passwordfile pwdfile deploy /home/ee/glassfish/sample/hello.war
Now the prompt for user name/password won’t appear.
<div class=“author”>Submitted by: <a href=“http://www.fromwheretowhere.net/”> Xuan Wu</a></div>
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
No command ‘asadmin’ found, did you mean: Command ‘amadmin’ from package ‘amanda-server’ (universe) asadmin: command not found
anyone?
as easy like this , before this a was installing glashfish with folder and sometimes doesnt work fine tks for all and regards.
I have a question but so far no one can help me, I went up a website on Digital Ocean but it is not being responsive, localmento on my computer it works in all sizes everything right but when I climb it in the DO is not responsive is what you get help me?
Thanks for the great article! I ran glassfish and deployed a servlet and everything seemed to work, but now for the second night in a row, when I woke up, my domain was no longer running and I had to manually tell it to run again. Can anyone tell me why this is happening and what I have to do? I am using Ubuntu with the LAMP stack.
This is good. But i failed to setup glassfish for my centos server following this tutorial although i changed the commands appropriately. Luckily i stumbled on this fine article and did just fine.
How much ram is it using ? If we use 1gb ram, how much will be free?
Thanks a lot!
if you are searching for a startup script for Glassfish 4, you can find one here:
http://kamwo.me/2013/08/installing-glassfish-4-on-ubuntu-lts/
Problem solved. My hostname wasn’t resolving to an IP, since it wasn’t specified in /etc/hosts … Thanks for your attention =)
All it shows is sshd (port 22), postgres (port 5432) and apache2 (port 80)… checked iptables rules (not that i have set any) and it is empty. Even added a rule to specifically open the admin port (4848) and it keeps saying it is already in use. Tried moving to port 4849, and it says it is already used also :-/ … Tried starting glassfish as regular user and root, no luck. This is disappointing, I’m about to downgrade to ubuntu 12 to see if this solves the problem. Should I try to install another program (not from repository) that uses any other non-privilegied port (>1024)??