Today is Thursday, 23rd September 2021

Archive for the ‘Glassfish’ Category

Install GlassFish 3.1 as a Windows Service

To install GlassFish 3.1 as a Window Service, you can use the create-service command. Follow these steps to setup the service:

Open an MS-DOS window (Run As Administrator)

cd {your_glassfish_home}\glassfish\bin

asadmin create-service --name domain1

This will create the service. You can verify this is the Windows Services control panel. By default, the service display name is domain1 GlassFish Server.

If you would like to change the display name of the service, then you can execute the following command. Be sure to put a space between DisplayName= and "GlassFish 3.1"

sc config domain1 DisplayName= "GlassFish 3.1"

If you no longer need the Windows service, you can delete the service with this command.

sc delete domain1

Also, you should delete all files in cd \glassfish\domains\domain1\bin

Additional documentation on the create-service command is available here.

Remote Deployments of WAR files with GlassFish v2

GlassFish v2 provides support for remote deployment of application. In fact, you have two options for deploying applications remotely

  1. GlassFish admin web application
  2. GlassFish asadmin console application

This blog post will focus on option 2, GlassFish asadmin console application. I prefer this approach since I can create a script that will automatically deploy the application. There is no requirement for me to click thru a web application interface. Simply create the WAR/EAR file and send it to the remote server. In my case, I’ll create an Ant script to automate this process.

Setting Up the Environment

You first have to set up your environment. We will use an Ant script to define the GlassFish Ant tasks.

<project name="glassfish-admin" default="list-components" basedir=".">

    <property name="asinstall.dir" location="c:/Sun/AppServer" />

    <property name="admin.user" value="admin" />
    <property name="password.file" location="password.txt" />

    <property name="" value="" />
    <property name="admin.port" value="4848" />

    <property name="appname" value="KillerApp" />
    <property name="war.filename" value="${appname}.war" />

    <path id="glassfish.class.path">
        <fileset dir="${asinstall.dir}/lib" includes="**/*.jar"/>

    <target name="sun-taskdef" description="Defines taskdefs for sun-appserv commands">
        <taskdef name="sun-appserv-deploy"
                classpath="${asinstall.dir}/lib/sun-appserv-ant.jar" />

        <taskdef name="sun-appserv-undeploy"
                classpath="${asinstall.dir}/lib/sun-appserv-ant.jar" />



On line 3, we define the directory of our GlassFish installation. You should update this accordingly for your environment.

Lines 5-6, define the admin user name and password file. I’ll come back to the password file later.

Line 8-9, define the name of the remote server and the port. In this example, the server is localhost ( but you can change this to any server on your network.

Lines 11-12, define the name of your application and the application file name.

Lines 18-27, define the GlassFish admin Ant tasks. In this example, we are defining the undeploy and deploy tasks. There are others available, see this reference for details.

The Password File

The password file must have the following format:


Deploying the Application

Now that we have the environment setup, we can cover the steps for deploying the application.

<project name="glassfish-admin" default="list-components" basedir=".">

    <!--  ... definitions from above section: setup environment ... -->

    <target name="deploy" depends="sun-taskdef" description="Perform remote deploy only to dev.">



Lines 7-15 perform the deployment of our application. This is accomplished with the sun-appserv-deploy task. The attributes for this task are self-explanatory. Once the task is complete, then the application is deployed to the remote server

Undeploying the Application

You can use the sun-appserv-undeploy task to undeploy the application. The following code fragment undeploys the application:

    <target name="undeploy" depends="sun-taskdef" description="Perform remote undeploy to localhost">

That’s it. Good luck with your application deployments!

GlassFish v2: Installing two Windows Services on same machine

I had a requirement to install two separate instances of GlassFish v2 on the same box. I initially looked at using separate domains but for infrastructure reasons, I needed to separate installations (long story).