How to install GlassFish on CentOS 7

Share on Social Media

Explore our detailed guide on how to install GlassFish on CentOS 7, including step-by-step instructions, necessary prerequisites, and troubleshooting tips for a smooth installation process. #centlinux #linux #java

What is GlassFish Server?

GlassFish is an open source application server for the Java EE platform. GlassFish project is initially started by Sun Microsystem and now sponsored by Oracle Corporation. GlassFish is free software and dual-licensed under two free software licenses CDDL (Common Development and Distribution License) and GPL (GNU General Public License).

Oracle GlassFish Server was the commercially supported. In Nov-2013, Oracle discontinued support of Oracle GlassFish Server while continuing open source updates. Thereafter, Oracle encouraged its customer to migrate to another alternate product Oracle Weblogic Server.

The only commercially supported fork of GlassFish available is Payara Server.

GlassFish Server Features

GlassFish Server is an open-source application server developed by the Eclipse Foundation. It serves as a reference implementation of the Java EE (Enterprise Edition) platform, providing a robust environment for deploying and managing Java-based web applications. Here are some key features and aspects of GlassFish Server:

  1. Java EE Compatibility: GlassFish fully supports the Java EE specifications, including servlets, JavaServer Pages (JSP), Enterprise JavaBeans (EJB), Java Message Service (JMS), and more. This makes it an ideal platform for developing and deploying enterprise-level Java applications.
  2. Open Source: As an open-source project, GlassFish is free to use and modify, with a strong community of developers contributing to its ongoing development and support.
  3. Modularity: GlassFish uses a modular architecture based on OSGi (Open Services Gateway initiative), allowing for flexible and dynamic deployment of services and applications.
  4. Administration and Management: GlassFish offers a comprehensive administrative console, as well as command-line tools, for managing server configurations, deploying applications, and monitoring server performance.
  5. Clustering and High Availability: GlassFish supports clustering and load balancing, enabling the deployment of applications in a highly available and scalable environment.
  6. Developer Tools Integration: GlassFish integrates seamlessly with popular Integrated Development Environments (IDEs) such as NetBeans and Eclipse, providing a streamlined development and deployment workflow.
  7. Extensibility: With support for various plugins and extensions, GlassFish can be customized to meet specific application requirements.

GlassFish Server is widely used for developing, testing, and deploying Java EE applications, offering a combination of performance, reliability, and ease of use.

How to install GlassFish on Linux 7
How to install GlassFish on Linux 7

System Specification

In this guide, we will walk through the step-by-step process of installing the GlassFish application server on a CentOS 7 system. For this setup, we’ll be using the open-source edition of GlassFish, paired with Oracle Java SE 8, which provides a stable and compatible runtime environment for deploying Java EE applications.

We are using a CentOS 7 virtual machine with following specification.

  • Hostname – glassfish-01.example.com
  • IP Address – 192.168.116.147/24
  • Operating System – CentOS 7.6
  • GlassFish Version – 5.0

Read Also: How to install GlassFish Server on CentOS 8

Recommended Training: Java Masterclass 2025: 130+ Hours of Expert Lessons from Tim Buchalka

533682 c10c 4
show?id=oLRJ54lcVEg&bids=1597309

Install Java SE on CentOS 7

Connect with glassfish-01.example.com using ssh as root user.

As a best practice, we always minimally install our CentOS 7 servers and then install required packages on demand.

We required wget and unzip commands to download and extract software respectively. Therefore, we are installing both of these packages using yum command.

yum install -y wget unzip

GlassFish 5.0 requires Java JDK 8. Therefore, we are downloading Oracle Java SE 8 from Oracle website.

Although, it is not necessary that, we must use Oracle Java SE 8, instead we can also use OpenJDK as well. Since we are using OpenJDK in our previous articles, therefore, we decided to try Oracle Java SE 8 this time.

wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm"

Install Java JDK 8u201 using yum command.

yum install -y jdk-8u201-linux-x64.rpm

Output:

Loaded plugins: fastestmirror
Examining jdk-8u201-linux-x64.rpm: 2000:jdk1.8-1.8.0_201-fcs.x86_64
Marking jdk-8u201-linux-x64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package jdk1.8.x86_64 2000:1.8.0_201-fcs will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
jdk1.8 x86_64 2000:1.8.0_201-fcs /jdk-8u201-linux-x64 288 M

Transaction Summary
================================================================================
Install 1 Package

Total size: 288 M
Installed size: 288 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 2000:jdk1.8-1.8.0_201-fcs.x86_64 1/1
Unpacking JAR files...
tools.jar...
plugin.jar...
javaws.jar...
deploy.jar...
rt.jar...
jsse.jar...
charsets.jar...
localedata.jar...
Verifying : 2000:jdk1.8-1.8.0_201-fcs.x86_64 1/1

Installed:
jdk1.8.x86_64 2000:1.8.0_201-fcs

Complete!

Set JAVA_HOME environment variable.

echo "export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64/" >> /etc/profile
. /etc/profile
env | grep JAVA_HOME

Output:

JAVA_HOME=/usr/java/jdk1.8.0_201-amd64/

Check Java version to verify installation.

java -version

Output:

java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

Install Glassfish on CentOS 7

Create a user to own Glassfish software.

useradd -s /sbin/nologin glassfish

Download Glassfish 5.0 from Glassfish website.

There are two editions of Glassfish are available, Web Profile and Full Platform.

Full Platform is the full fledge Java EE server, with complete Java Platform support. Whereas, Web Profile is the subset of Glassfish Full Platform, provides only commonly used elements.

Here, we will download Glassfish 5.0 Full Platform.

wget http://download.oracle.com/glassfish/5.0/release/glassfish-5.0.zip

Extract glassfish-5.0.zip file.

unzip -d /opt/ glassfish-5.0.zip

Change ownership of /opt/glassfish5 directory.

chown -R glassfish:glassfish /opt/glassfish5/

Create a systemd service to autostart Glassfish server.

vi /usr/lib/systemd/system/glassfish.service

and add following directives therein.

[Unit]
Description = GlassFish Server v5.0
After = syslog.target network.target

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

[Install]
WantedBy = multi-user.target

Start and enable glassfish.service.

systemctl enable glassfish.service
systemctl start glassfish.service

Glassfish uses following Service ports.

  • 4848 – Administration Console
  • 8080 – HTTP Service
  • 8181 – HTTPS Service

Allow Glassfish Service ports in Linux Firewall.

firewall-cmd --permanent --add-port={4848,8080,8181}/tcp
firewall-cmd --reload

Add Glassfish binaries to PATH environment variable.

sed -i 's/^PATH=*/PATH=/opt/glassfish5/bin:/g' ~/.bash_profile

Set password for Glassfish 5.0 Admin user.

asadmin --port 4848 change-admin-password

Output:

Enter admin user name [default: admin]>
Enter the admin password>
Enter the new admin password>
Enter the new admin password again>
Command change-admin-password executed successfully.

By default, Glassfish Admin Console is running as a clear text HTTP service. Run following command to enable secure administration console.

asadmin --host glassfish-01.example.com --port 4848 enable-secure-admin

Output:

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 glassfish.service.

systemctl restart glassfish.service

After restarting glassfish.service, we are not able to access the Glassfish Admin Console.

Thanks to M.S. Dousti at StackOverflow, we come to know about this bug. It is caused by the use of an older version of Grizzly module. As a workaround, he suggested to upgrade the grizzly-npn-bootstrap.jar to a newer version.

Therefore, we have downloaded and upgraded grizzly-npn-bootstrap.jar as per his advice.

cd /opt/glassfish5/glassfish/modules/endorsed
mv grizzly-npn-bootstrap.jar grizzly-npn-bootstrap.jar.1
wget https://search.maven.org/remotecontent?filepath=org/glassfish/grizzly/grizzly-npn-bootstrap/1.9/grizzly-npn-bootstrap-1.9.jar -O grizzly-npn-bootstrap.jar
chown glassfish:glassfish grizzly-npn-bootstrap.jar

Restart glassfish.service.

systemctl restart glassfish.service

Browse URL https://glassfish-01.example.com:4848/ from a client’s browser. You have to ignore certificate warning and add exception in your browser.

GlassFish Server Administration Console 1
GlassFish Server Administration Console 1

We have reached at the login page of Glassfish 5.0 Admin Console.

GlassFish Login
GlassFish Login

Login as Admin user with password, that we have set in previous steps.

GlassFish Dashboard
GlassFish Dashboard

We have successfully login to Glassfish Admin Console.

Now, Browse URLs http://glassfish-01.example.com/ or https://glassfish-01.example.com/ from a client’s browser.

Both URLs will bring you to the same page. The only difference is that, former will serve you a clear text HTTP version, however the later will serve a encrypted HTTPS version of the same webpage.

GlassFish Server Administration Console 2
GlassFish Server Administration Console 2

We have successfully install Glassfish on Linux 7 server.

Frequently Asked Questions (FAQs)

What is GlassFish?
GlassFish is an open-source application server for Java EE (Enterprise Edition) applications, developed by Eclipse Foundation. It supports servlets, JSP, EJB, and other Java technologies.

What are the prerequisites for installing GlassFish on CentOS 7?
You need a CentOS 7 system with Java (JDK 8 or later) installed, sufficient disk space, and basic Linux command-line knowledge.

Do I need root access to install GlassFish?
No, GlassFish can be installed under a regular user, but you may need root access to configure system-wide settings like firewall rules or services.

How do I start and stop GlassFish after installation?
GlassFish can be started or stopped using the asadmin utility, which is included in the installation.

How can I access the GlassFish admin console?
After starting GlassFish, the admin console is accessible via a web browser at http://<your-server-ip>:4848 by default. You’ll need the admin credentials set during installation.

Final Thoughts

Installing GlassFish on CentOS 7 is a straightforward process when the system is properly prepared with the necessary Java environment and firewall configurations. By following the steps outlined, you’ve successfully set up a powerful Java EE application server ready to deploy enterprise-grade applications. To ensure long-term stability and security, remember to keep GlassFish updated, monitor logs, and follow best practices for server hardening.

Optimize your cloud infrastructure and secure your servers with my AWS and Linux administration services. Let’s ensure your systems run smoothly. Connect with me on Fiverr now!

Reach out for expert advice and ensure your GlassFish setup is done correctly and efficiently!

Looking for something?

8 responses to “How to install GlassFish on CentOS 7”

  1. Ricardenator Avatar

    Thank you for your post!

    I installed my new version of glassfish in a few minutes!

    But, there are two issues in your post:
    1. There is a recent Oracle Java License Update just after your post. I can't install Oracle JDK version.
    2. In the step for update grizzly-npn-bootstrap.jar is a typo in –O option. It's only with one hyphen. -O is the correct spell.

    Thank you again!

  2. Ahmer M Avatar

    Hi,
    It is good to here from you.

    1. You can use openjdk instead of Oracle JDK.
    2. Thanks for point out this typo. It has been corrected now.

  3. Anonymous Avatar
    Anonymous

    After downloading Grizzly jar one should chown it. Just for consistency.

  4. Ahmer M Avatar

    Hi,
    Agreed with you.
    Although the configurations work fine, but it is better to change the file owner for consistency.

    Updating above article as per your advice.

  5. oliver Avatar

    Hi, I need help.
    When "enable secure administration console" after, i can´t access console.
    Send message in explorer "can´t acces web site".

  6. Ahmer M Avatar

    Please contact us on our facebook page.

  7. DudeBoy Avatar

    In 2022 it still works perfectly, in my case due to limitations of the application I couldn't use a newer version of glassfish and I decided on this stack and it worked, I lost 2 days trying to use glassfish 5 in ubuntu, but thanks to your tutorial in half an hour I had everything working thanks

  8. Ahmer M Avatar

    Thanks for your feedback. Stay connected.

Leave a Reply