ziggy
ziggy

Reputation: 15876

Maven vanilla project for EJB2 and EJB3

I have a requirement where i have two develop two projects, one with EJB2.1 and one with EJB3.x. The EJB2.1 will be an extension to an existing project hence the reason it is v2.1 and cannot be migrated to 3.x just yet.

Both projects have to be built using Maven and this is where i am struggling. Believe it or not, i have spent the last 3 days trying to find a simple example of a stateless EJB project built using Maven but have had no luck.

Here are a couple of pointers i found through googling but none of them work.

Eclipse allows you to create an EJB3 project. Latest versions dont allow you to create EJB2 projects. Also, you cant create a Maven EJB project.

I have tried the following archetypes in Maven but none of them work

ejb2-j2ee13
ejb2-j2ee14
ejb-javaee6
ejb-jee5
ear-jee5
ejb-jee5

The above archetypes are only for EJB3 or for those that are for v2.x there will be some dependencies missing.

I also found the following tutorials on the Jboss documentation http://anonsvn.jboss.org/repos/jbossas/projects/ejb3/trunk/docs/tutorial/reference21_30/. I intend to use the EJBs on Jboss v5.1. The projects on this URL are Maven projects but they also complain about missing dependencies (The ant build does work).

If anyone can point me to where i can download a vanilla "Hello world" maven project for both EJB2.x and EJB3.x (That would run on Jboss 5.1.x) i would really appreciate it.

I have spent so much time on google and have finally decided to ask here as i am not getting anywhere. I suspect that maybe they are making it difficult to find these dependencies as they dont want people to use EJB2.x anymore. The problem is some people have no other option.

Upvotes: 0

Views: 1502

Answers (1)

Stefan
Stefan

Reputation: 1000

you really dont need the archetype for Java EE5, or JEE6 there is so little boilerplate code, that all you need is a regular java archetype and add the dependency for

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
</dependency>

or

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>5.0</version>
    <scope>provided</scope>
</dependency>

add your beans.xml and you are done. Avoiding any JBoss depdencies is actually a good practice, as this ensures your application remains portable.

Note: If you want to mock or use any classes from the respective javax.XXX packages, you will need to include your application server specific dependencies into your maven test scope. This is because Sun/Oracle altered the bytecode of the API jars, to guarantee nobody accidently uses these classes, instead of the ones provided by the server.

Upvotes: 1

Related Questions