Skip to main content

Java EE Continuous Integration powered by Maven & Glassfish

Posted by felipegaucho on October 9, 2009 at 11:48 AM PDT

Can you compile, deploy and test your Java EE projects with just
1 line of command? Check it out.

I have no time for documentations lately, but I prefer to give
you a chance to early adopt my build script and take your own
conclusions. Following the steps below, you will have my Java EE 5
application running in your Glassfish v2.1 server - including test data
populated in the MySql database.

What the script do is:

  1. Compile, do unit tests and pack the href="">Arena-PUJ Project.
  2. Deploy the RESTful web-service. (*.ear)
  3. Populate the MySql with the test data.
  4. Execute the integration tests
  5. Deploy the DWR web application (*.war)

The magic is done by a set of of href="">

commands powered by Shell Script and the href="">
AntRun Plugin
. You can href="">checkout
the project with all artifacts and ask me if you have any suggestion or
doubts. Have fun :)

Important: the current version of the
script only works on UNIX-like machines because it uses
Shell Scripts. I created and tested the script on the Ubuntu OS and I
didn't have interest time to translate it for a DOS
script (*.bat). So if you are using Windows, sorry but your
blog reading finishes here. If you are a Windows user and you would like
to contribue with a BAT file, please send that to me and you will
receive the proper credits - it may be a good contribution to my href="">pet project


No, you can't skip these non pleasant steps, but at least you
need to do it just once.

Check if you have all software you need:

  1. Java 6.x
  2. Maven
  3. MySql 5.x
  4. Mercurial
  5. Glassfish
    * the ones living in the future can try the latest
    v3 b66
    and please do contribute with the href="">FishCat if you find
    a bug.

After installing everything, startup the database and the
application server. Open a terminal and type:

	sudo service mysql start
asadmin start-server

* By default MySql will be already
running as service, so you probably can skip the first step.

Creating the passwords file and the arena database

For portability and obvious security reason, I couldn't type the
password direct on the script, so I let the users to use their own local
passwords. Due to that reason you have one more boring step to proceed:
to create a passwords file and save it as ~/.passwords,
containing the following property values:


Known limitations: the current Java code of
Arena-PUJ only works for IMAP secure SMTP servers. I plan to review the
code making it more generic, but for now it is guarantee to work only
with a GMail-like SMTP server. I couldn't find an elegant way of using
the AntRun plugin with the Shell Script, so I hard coded the ~/.passwords
in the script. Despite that, if you invoke it by line command, you can
pass an argument with the name of the passwords file - I just couldn't
get it working smoothly with the Maven plugin :(. The project should
work with other databases, since I am not using any MySql specific trick
in the domain model - but I never tried and I can't guarantee if it will
really be portable for other DBs. You need at least to update the
deployment descriptors if you plan to test it on other Java EE Servers
and the persistence.xml if you will use other Database - and please tell
my if you want to try it, I am very interested about the results.

Building and deploying

After installing the software and creating your configuration
file, the good news: your job is done, now it is time for my magic
script to show its strengths. Open a terminal and type the following

	hg clone
cd puj~arena
mvn clean install

Now you take a coffe, watch the screen and smile - it is time to
see why Glassfish is my preferred Application Server :)

Successful build? just access href="http://localhost:8080/arena-dwr/">http://localhost:8080/arena-dwr/

Integrating with Hudson

The built system presented here is a pure Maven Script so it is
piece of cake to create a Hudson job to run the script. You can href="">see
here the build history of the Arena-PUJ.


If you know me you know how I hate manual configuration steps and
other traps the big commercial projects impose in our lives. To make my
own and small project clean and easy is the minimum my slim ego requires
to continue with me - but I have just few spare hours a week to push
this pet project to a higher level so I appreciate any enhancements and
suggestions you can bring to me. It is a new project and I am pretty
sure it will get much better in the near future. All commands in the
build script can be done through the Glassfish Administration Console -
it contains no magic secrets actually.


This beautiful piece of configuration was made better due to the
tips and discussions in the Brazilian Java Community and always with the
friendly support from the Glassfish's team. My best thanks for all of
you and a special kudo to href="">M


Not bad, I wouldn't say that

Not bad, I wouldn't say that this is a problem just for big commercial projects, but I certainly dislike it also. In my case, I went a bit further and using an embedded database and embedded servlet container, I can start with a 32Kb ant script and with Ant, Java 6 and CVS as requirements, my script checks out, installs, compiles, runs and executes the tests of the project. Not that one would want to do that every time, as downloading the dependencies can take a while :). But after the first time, it makes running the tests quite easy, as in your example. In any case, using an embedded DB and an embedded container might lower your initial requirements even more, if you don't have those as fixed requirements for any given reason. S!