Felipe Gaúcho works as senior software engineer at Netcetera AG in Switzerland. He is a well known Brazilian JUG leader and open-source evangelist. Felipe works with Java since its early versions and has plans to keep that Java tradition as it is. When he is not coding, he prefers to listen reggae and travel around with his lovely wife Alena and his son Rodrigo. Felipe is a DZone MVB and is not an employee of DZone and has posted 29 posts at DZone. View Full User Profile

Java EE Continuous Integration Powered by Maven & Glassfish

10.10.2009
| 5782 views |
  • submit to reddit

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 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 Glassfish's ASADMIN commands powered by Shell Script and the Maven AntRun Plugin. You can 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 pet project.

Setup

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 2.x
  3. MySql 5.x
  4. Mercurial
  5. Glassfish v2.1 * the ones living in the future can try the latest v3 b66 and please do contribute with the 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:

	AS_ADMIN_MASTERPASSWORD=glassfish_password
	AS_ADMIN_USERPASSWORD=glassfish_password
	AS_ADMIN_ALIASPASSWORD=glassfish_password
	MYSQL_USER=mysql_user
	MYSQL_PASSWORD=mysql_user_password
	ASADMIN_USER=glassfish_password
	DB_URL=jdbc\\:mysql\\://localhost\\:3306/arena
	MAIL_HOST=smtp.gmail.com
	MAIL_USER=mailuser
	MAIL_FROM=mailuser@gmail.com
	MAIL_SMTP_USER=mailuser@gmail.com
	MAIL_SMTP_PORT=465
	MAIL_SMTP_PASSWORD=guesswhat

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 commands:

Updated: please check the new instructions here.

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 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 see here the build history of the Arena-PUJ.

Summary

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.

Acknowledgment

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 Márcio Correia from CEJUG.

From http://weblogs.java.net/blog/felipegaucho

Published at DZone with permission of Felipe Gaúcho, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

John Ferguson Smart replied on Sat, 2009/10/10 - 5:42pm

Sound's cool - I'll check it out

Felipe Gaúcho replied on Sun, 2009/10/11 - 1:58am

I just upgraded everything to Glassfish V3 and it works fine in the newest version. I will update the blog with the little modifications and publish the new artifacts (scripts and deployment configurations) asap.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.