Java EE Continuous Integration Powered by Maven & Glassfish
Join the DZone community and get the full member experience.Join For Free
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:
- Compile, do unit tests and pack the Arena-PUJ Project.
- Deploy the RESTful web-service. (*.ear)
- Populate the MySql with the test data.
- Execute the integration tests
- 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
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.
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:
- Java 6.x
- Maven 2.x
- MySql 5.x
- 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
* 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_FROMemail@example.com MAIL_SMTP_USERfirstname.lastname@example.org 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.
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 Márcio Correia from CEJUG.
Opinions expressed by DZone contributors are their own.