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!

Did you like my blog post?

Signup now and receive an email when I publish new luv2code content.

I agree to have my personal information transfered to AWeber ( more information )

I will never give away, trade or sell your email address. You can unsubscribe at any time.

1 Comment

  1. Comments  raj   |  Thursday, 12 September 2013 at 3:57 pm

    simple and best examples.

Leave a Reply