Monday, October 20, 2008
Thursday, October 09, 2008
One of the most boring things in EJB development is that we need container. Compile-Build-Deploy-Run_some_testing_code - this is to long cycle to repeat it frequently without some kind of automation. I'll show you one of the possible ways to simplify this stuff. There are others, but I didn't tried them (I mean jboss microcontainer here). It's not complex, but it works and probably could be portable solution for not only my case.
So, my working environment is the following : Maven 2, JBoss 4.2.2 GA, jUnit 3.8.1 and of course EJB3. Build lifecycle with Maven 2 consists of some phases, like "...compile,test,package,integration-test...". Ok, with package and compile phases all is clear. Test... we need jboss to be up and running before we can test anything. How to start and stop jboss automatically during build ? The answer is Cargo with Maven2 plugin.
Cargo is a thin wrapper around existing containers (e.g. J2EE containers). It provides different APIs to easily manipulate containers.
Now we can assign "start container" and "stop container" goals to some Maven 2 build phase. First of all, we are interested in integration-test. Also we need to skip junit tests before integration test. To achieve this I'm using this config for cargo plugin :
And this for surefire - to be able to run junit tests on integration-test phase, after container started at pre-integration-test phase :
<plugin>I haven't any luck with "standalone" type configuration. I should say that when"existing" jboss installation is used here, overall process is quite fast:
[INFO] -------------------------------------------42 seconds to compile code, package jar, copy jar to deploy dir, start jboss, run junit test, stop jboss and all this by doing just "mvn install" !
[INFO] BUILD SUCCESSFUL
[INFO] Total time: 42 seconds
[INFO] Finished at: Thu Oct 09 15:15:39 EEST 2008
[INFO] Final Memory: 9M/19M
Complete source code available via svn here.
Time can be very different. My hardware is HP 6820s laptop. BTW, executing "mvn -o install" takes 23 sec :)
at 1:41 AM
Friday, October 03, 2008
My posts (the first and the second) about how to build EJB3 using Maven 2 was very popular. This post is some kind of update, but now, with complete source code. BTW, I'm going to publish some of sources I mentioned at my blog posts, since readers are asking for them. I mean source code from this post at minimum.
So, here it is ! In my further posts I'm going to highlight some of pitfalls one can face with.
at 7:00 AM