Getting started with GlassFish 4With the recent release of Java EE 7 and GlassFish 4, it's a good time to revisit the basics of GlassFish: from downloading, installing to (un)deploying an application. We also cover the same topics in the first part of our GlassFish Webinar Series
The rest of this post assumes an installation on a Linux environment, preferably RedHat like (Oracle UL, CentOS, etc), as GlassFish 4 is certified for RHEL.
The most important requirement for GlassFish 4 is Java SE 7. Make sure you have the JDK for release 7 installed.
> java version "1.7.0_17"
Also verify that JAVA_HOME is set to the correct JDK directory.
The installer also tries to start GlassFish, so if the network ports 4848 and 8080/8081 are not free, this will result in errors. A minimal amount of disk space is required, at most 250 MB should be enough.
Downloading the install files
On the GlassFish 4 download site there are two options available:
1) Zip file
The zip file distribution is the fastest way to get started with GlassFish 4. Just unzip the file and run the asadmin command to start.
unzip -d /opt/oracle/ glassfish-4.0.zip
The installer files are available in multiple flavors, all executing as a graphical installer. The most important distinction with the zip file here is the option of installing only the Java EE Web Profile, which is more lightweight than the full edition, if you only need to run Java Web Applications.
Running the installer for the full edition:
or for the web edition
The graphical installer also allows you to create answer files, which can be used to customise port numbers. The graphical installer will run normally, but it will not actually install GlassFish.
Later this answer file is used by the installer in silent-mode.
Creating the answer file:
./glassfish-unix.sh -n <answer_file>
Running in silent mode:
./glassfish-unix.sh -a <answer_file> -s
In addition, the graphical installer is downloadable with support for multiple languages.
After installing a directory structure will be created in the install location. The following directories are interesting to take a look at:
Location of asadmin and updatetool executables
Location of glassfish start and stop scripts
Root directory for the preconfigured domain
Location for the configuration of the domains
Location of server.log
Starting and stopping the domain
Both installers come with a preconfigured domain named "domain1". This domain can be controlled using the asadmin tool. Starting the domain on the command-line is done as follows:
The start-domain command has an optional domain name parameter, but the default is "domain1".
The domains available are listed with the following command:
Similarly to starting the domain, it can also be stopped with asadmin:
Autostart GlassFish on boot
The asadmin tool can also create init.d scripts so that it will be started on boot. This will not restart the server after crashes, but will start up GlassFish when the server is restarted.
This creates an init.d script in /etc/init.d/GlassFish_domain1. When the service is started like this, it should also be stopped with the same init.d script.
Opening the Admin Console
After starting the domain, the Admin Console will be available on http://localhost:4848. Initially no login is required.
For the most part, the Admin Console offers the same configuration options as the asadmin tool, but is definitely more user-friendly.
Deploying and undeploying applications
Again, the simplest way to deploy an application is to use the asadmin tool. First download the sample WAR file from the GlassFish website.
./asadmin deploy hello.war
After deploying the application will be available at http://localhost:8080/hello. Take note that this is a different port than the Admin Console.
The applications can be listed an undeployed with asadmin (using the app name, not the WAR):
./asadmin undeploy hello
The same can be accomplished with the Admin Console in Applications > Deploy. Here you have more customization options, for example setting the context root or enabling precompilation of JSP's.
Running the updatetool
GlassFish comes with the updatetool packaged, or with a stub if it was disabled during installation. This update tool will look for newer versions of GlassFish and apply the updates. It is located in the same directory as asadmin.
On CentOS 6.4 64-bit it does not work out-of-the-box, since a few libraries appear to be missing, so the following error message is displayed:
error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
Install the required packages to run updatetool normally:
sudo yum install libstdc++.so.6 libgtk-x11-2.0.so.0 libXxf86vm.so.1 libSM.so.6 libpk-gtk-module.so libcanberra-gtk-module.so
In our webinar series on GlassFish 4, we'll discuss more advanced topics such as: high availability, monitoring, migration of application. Check the agenda for more information.