| 3 May 2009 |
Although I am pretty familair with EJB3 I decided to get prepared for my next certificate SCBCD by going through the book 'Enterprise JavaBeans 3.0' by Burke and Monson-Haefel. A good thing about the book is that they added a 'workbook' in which exercises and coding examples are described. However, there is also a 'disadvantage' and that is that they use Ant to do the building, deploying and running of the code. And they use JBoss4.0 as an application server, which was the logical choice when the book came out, I guess, but is outdated nowadays. So I decided to rewrite the example a little as an exercise by making use of Maven2 for the building and deploying and do this on JBoss5.0.1 that has been released a few weeks ago.
While creating the Maven builds for the first chapter I discovered there are actually several ways to do this, depending on the extend you want to use Maven for this:
- Minimal use of Maven
- Medium use of Maven
- Optimal use of Maven
- create a Maven project
- copy code to maven code dir
Next step is to copy the (re)sources to the place where Maven2 expects it (also a good point to remove the default generated classes App.java and AppTest.java. You will get a setup like this:
- modify pom
-
<jboss.home>/usr/local/jboss</jboss.home>
- modify the 'persistence.xml'
-
xmlns="http://java.sun.com/xml/ns/persistence"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
-
version="1.0"
In this option I only use Maven to create the ejb-jar. The deployment and the execution of the client to test the EJB is done manually.
I use Maven to create the ejb-jar file, a separate ear file and I deploy it with Maven at a running JBoss container. Running the client is still done 'manually'. Ear project can be reused to deploy ejb jars of other chapters.
I extend the setup by performing the unit test in Maven by making use of OpenEJB before it is deployed to JBoss. This way I am sure the bean is working correctly when it is deployed on JBoss.
In this post I describe the steps for option 1.
Steps to make this work:
This steps is obvious. Just create a standard Maven project with the command mvn archetype:generate like described in detail here.
Next step is to enrich the pom with all dependencies necessary to compile the code. And these are a lot of dependencies when using JBoss to compile against. The complete pom can be found
here. I have added this property to my settings.xml as it is used in the pom:
By using the new JBoss version it appears that the original persisitence.xml isn't working anymore. I had to add the following to it:
If you don't add this I got the error:
DEPLOYMENTS IN ERROR:
Deployment "vfszip:/usr/local/jboss-5.0.1.GA/server/default/deploy/ch4.jar/" is in error due to the following reason(s): org.jboss.xb.binding.JBossXBRuntimeException: Failed to resolve schema nsURI= location=persistence
That's it. You can now build an ejb-jar file and copy it to the JBoss instance by hand. And you can run a client program to call your bean.
In the next post I will show you how you can use Maven to perform the deployment for you and how you can use a 'standalone' client to test your ejb deployment in Netbeans.


11 comments to 'EJB3 with JBoss5 and Maven2'
8 May 2009
[...] EJB3 with JBoss5 and Maven2 [...]
18 May 2009
[...] EJB3 with JBoss5 and Maven2 [...]
31 July 2009
Hi Pascal
This is very interesting article. I am a newbie and trying to make this work.
Can you please update step 1, what are the groupId, artifactId, version and package that you entered?
In step 3, when I try to add in my settings.xml as
C:\jboss-5.0.1.GA
I am getting the error
Error reading settings.xml: Unrecognised tag: 'jboss.home' (position: START_TAG
seen \r\n\t... @2:14)
Line: 2
Column: 14
I am using Maven version: 2.0.10. Is there anything that needs to be done?
Thanks
Kevin
31 July 2009
My local settings.xml is as follows
C:\jboss5.0.1.GA
31 July 2009
There is a problem in posting xml tags.
My local settings.xml file is something similar to this one.
settings
jboss.home C:\jboss-5.0.1.GA jboss.home
settings
31 July 2009
Hi Kevin,
I am looking how to allow XML tags in the comments but haven't found out yet.
About your questions:
The properties in your settings.xml must be surrounded with a 'properties' tag.
ABout the parameters in step 1: this is up to you what you fill in. This will be used by Maven to create your project with these values. If this 'generate' archetype isn't working for you you can use the 'old' version: 'create' archetype as described here: http://maven.apache.org/plugins/maven-archetype-plugin-1.0-alpha-7/examples/simple.html
31 July 2009
Thank you Pascal. That helped me.
Now I have another problem. when I try to compile with command
mvn compile
I am getting the following error
annotations are not supported in -source 1.3 (use -source 5 or higher to enable annotations)
I am using jdk 1.6.
I am not that familiar with maven. It seems there is someplace where I need to set the jdk version. Can you please let me know the file name and what needs to be modified?
Thanks
4 August 2009
Hi Kevin,
I sent you a mail how to solve that. Hope that helps.
5 August 2009
Thank you very much. That helps.
18 November 2009
[...] with JBoss5 and Maven2 (part 2) 8 May 2009 Pascal Alma As I stated here I see three levels of using Maven2 to build and deploy your EJB3 application with JBoss5 as [...]
18 November 2009
[...] with JBoss5 and Maven2 (part 3) 18 May 2009 Pascal Alma As I promised here this is the last part about using Maven2 to build, test and deploy an EJB3 application to JBoss5. [...]