Continuous deployment on Glassfish

Okay, how do we deploy to glassfish from maven on jenkins? Let’s try org.glassfish.maven.plugin:maven-glassfish-plugin first.

pom.xml

<plugin>
    <groupId>org.glassfish.maven.plugin</groupId>
    <artifactId>maven-glassfish-plugin</artifactId>
    <version>2.1</version>
    <executions>
        <execution>
            <goals>
                <goal>deploy</goal>
            </goals>
        </execution>
    </executions>
</plugin>

~/.m2/settings.xml

<profile>
    <id>glassfish</id>
    <activation>
        <activeByDefault>false</activeByDefault>
        <property>
           <name>glassfish.version</name>
           <value>3.1</value>
        </property>
    </activation>
    <properties>
        <glassfish.home>/opt/servers/glassfish-3.1</glassfish.home>
    </properties>
</profile>

Unfortunately, maven tries to go to http://maven.ocean.net.au/external which is returning 503’s today. After some hoops and loops it still doesn’t work, so let’s try a different approach.

pom.xml, revisited

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.1.1</version>
    <configuration>
        <!-- Do not wait after the container is started -->
        <wait>false</wait>

        <container>
            <containerId>glassfish-3x</containerId>
            <home>/opt/servers/glassfish-3.1</home>
            <output>${project.build.directory}/glassfish/container.log</output>
            <append>false</append>
            <log>${project.build.directory}/glassfish/cargo.log</log>
        </container>

        <configuration>
            <deployable>
                <groupId>com.example</groupId>
                <artifactId>application-web</artifactId>
                <type>war</type>
                <properties>
                    <context>/</context>
                </properties>
            </deployable>
        </configuration>

    </configuration>
</plugin>

It works, deploys, undeploys, but requires setting app server each time. Plus by going against maven plugin shorthand naming, requires an excruciatingly tedious

m3 -DskipTests clean package org.codehaus.cargo:cargo-maven2-plugin:undeploy \
org.codehaus.cargo:cargo-maven2-plugin:stop \
org.codehaus.cargo:cargo-maven2-plugin:start \
org.codehaus.cargo:cargo-maven2-plugin:deploy

to run.

AAAAAAAAA! I feel I’m doing something wrong here, so… is there another way? Yes! 🙂

Actually, since I am using Glassfish and it includes a first-class CLI tool called asadmin (short from Application Server admin, as Glassfish used to be called Sun Application Server), let’s use it.

#!/bin/bash

asadmin="/home/glassfish/glassfish/bin/asadmin" 
$asadmin undeploy dashboard-web-0.1-SNAPSHOT
$asadmin restart-domain domain1
$asadmin deploy $WORKSPACE/application/application-web/target/application-web-0.1-SNAPSHOT.war

Put that as a script somewhere and execute as a post-build step after a successful build in Jenkins et voila, a contiuously deployed dev version.

Author: ags

bio

2 thoughts on “Continuous deployment on Glassfish”

  1. Why is it inportant to undeploy first, and then redeploy?
    Can’t u just deploy and let glassfish take care of it?

  2. Simple answer is: because the app was a bit messy ;(
    When we cleared this up, we started to do redeploy without the restart each time 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.