Monday, 24 November 2008

How to install glassfish Java application server

I installed Glassfish application server few days ago, for the first time.
Although it has no GUI installer and you have to do it all by typing in console window, it’s a quite easy thing to do…

I needed new Java app server for some job to be done, and it was all up to me to decide which one to use…

At the end, I decided to use either Glassfish or JBoss.

Since I worked with glassfish that comes with NetBeans, and was very pleased with it , it was probably quite easy to guess that my choice is going to be glassfish…
After all, glassfish is nothing else then Sun Java System Application Server , but without GUI installer and some extra options in it and, of course, without support…

So, glassfish it is!

There’s a lot of documentation on how to install and start it, and you can easily find out everything you need to do that…

Since all the information that you need to know when installing this application server are on several locations on the internet, I will try to explain the entire process on how to install glassfish on windows so you don’t have to look for it on the net, hoping to save you some time…

- Prerequisites

In order to install glassfish, we need to have JDK 1.5 , or some newer version installed on the computer on which the glassfish will be running.
Be aware: not just JRE , but JDK + JRE!

So, install it and set all system variables ( JAVA_HOME, PATH and CLASSPATH ).

- Installation

Let’s start with downloading binaries.
Go to the and download the latest stable version.

The installation file is java archive. I downloaded

Let’s take this file, and place it where you want to install it.

Tip: Wherever you place it, when you start the installation, the installer itself will create a “glassfish” folder on that location and place all the files in it…

I don’t know why, but I like to install servers and all similar applications in root of C disk and not in “Program files”, so I’ll create a folder called “Sun” on the C disk , and copy glassfish-installer-v2ur2-b04-windows.jar in it , because I want my server to have a “C:\Sun\glassfish” path.

We will start installation by typing

java –Xmx256m –jar glassfish-installer-v2ur2-b04-windows.jar

It will first ask you to read ( scroll all the way down ) some licence agreement , or something like that. After you accept it, the installer will copy all the files to the “.\glassfish” folder.
The installation is almost finished. There are just few more things that needs to be done.
First of all, go to the <GLASSFISH_HOME>\lib\ant\bin\ and type

ant –f setup.xml

or from within installation directory type

.\lib\ant\bin\ant –f setup.xml

This way, we created a new domain: domain1.
Before you do this, you can open it with some editor and change the default names and ports, but if there’s no special need to do it – just don’t . Install it with default settings.

Now add the <GLASSFISH_HOME>\bin folder to the environment variable “PATH” ( then restart console window) , and at this moment your glassfish is installed and you can start it by typing

asadmin start-domain domain1

and stop it by typing

asadmin stop-domain domain1


We now have two problems:

- Glassfish does not have any tool to help you create a windows service for it , and since it is an application server , we need to have it running as a windows service. Fortunately, glassfish has executable called appservService.exe which communicates with the windows service controller, and we’ll use it later…

- Glassfish was developed using Java and therefore it uses JVM. But, when a user logs off - JVM turns off as well, and this is something we do not want to happen with our application server when the user that started it logs of…We need to control this.

So, the solution for the first problem is provided to us by Ryan de Laplante , who made a GlassfishSvc.jar file that will help us create a windows service for glassfish server.
Go to
and download this file.
After you downloaded it, copy it to your installation folder ( in my case: “C:\Sun\glassfish\” ) and run it with

java –jar GlassfishSvc.jar –i

First problem solved ;-)

We will solve the second problem with –Xrs JVM option.

Open <GLASSFISH_HOME>\domains\domain1\config\domain.xml file and add the following line:


to the part of the file that has many other <jvm-options>something…</jvm-options> tags…

Now, as I red, many people reported that this doesn’t work on windows 2003 server, so if this didn.t help, go to <GLASSFISH_HOME>\lib\processLauncher.xml
and add a line

<sysproperty key=”-Xrs”/>

inside a

<process name=”as9-server”>


What I did first, I added a line to <GLASSFISH_HOME>\domains\domain1\config\domain.xml , restarted a server and logged off, but the JVM turned off also. This didn’t work for me…

Then, I tried second option, restarted a server, logged off - but it didn’t work as well…???

Then, I restarted windows, (server started by itself because it’s now a windows service), logged of and everything worked well…
If someone asks me which solution helped me – I would tell him “I really don’t know, and I don’t care…”

So, that’s it!
Now you have a glassfish application server installed, you have a windows process for it and your JVM won’t turn off causing the server to shut down as well when you log off, and that is all we needed…

I hope this text will help someone…

Good luck and enjoy your glassfish!

No comments: