Using maven-ejb-plugin and creating an EAR

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Using maven-ejb-plugin and creating an EAR

Eric B
Hi,

I've got a JEE project that has EJBs being accessed both locally and
remotely.  But I'm not entirely sure how to use the ejb-plugin and the
ear-plugin to create my ear.

At the moment, I'm using the ejb-plugin to create my EJB artifact:

<modelVersion>4.0.0</modelVersion>
<groupId>root.project</groupId>
<artifactId>ejbs</artifactId>
<packaging>ejb</packaging>
<version>1.0</version>
<name>enterprise java beans</name>

...
...
<build>
<plugins>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<ejbVersion>3.0</ejbVersion>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>


I am then including the generated ejb in my WAR as follows:
<modelVersion>4.0.0</modelVersion>
<groupId>root.project.servlets</groupId>
<artifactId>servlet</artifactId>
<packaging>war</packaging>
<name>servlet</name>
...
<dependencies>
<dependency>
<groupId>root.project</groupId>
<artifactId>ejbs</artifactId>
<version>${project.version}</version>
<type>ejb</type>
</dependency>
...
...
</dependencies>


Finally, in my EAR, I have the following:
<modelVersion>4.0.0</modelVersion>
<groupId>root.project</groupId>
<artifactId>ear</artifactId>
<packaging>ear</packaging>
<version>1.0</version>
<name>ear assembly</name>
<dependencies>
<dependency>
<groupId>root.project</groupId>
<artifactId>ejbs</artifactId>
<type>ejb</type>
</dependency>
<dependency>
<groupId>root.project.servlets</groupId>
<artifactId>servlet</artifactId>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<defaultLibBundleDir>lib/</defaultLibBundleDir>
<skinnyWars>true</skinnyWars>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>


The EAR builds properly. The issue that I have is that is that the EJB
module is added in both the root of my EAR and in the
servlet.war/WEB-INF/lib folder. The classloader then finds 2 copies of the
classes in my application - one from the WAR and the one from the EAR.

Obviously, this is not right. But I am not sure what the right way to do
this is. Am I obliged to generate an ejb-client and include the ejb-client
in my WAR only? However, then I will still have 2 copies of the interface -
one in the ejb jar and one in the ejb-client.jar. How does this improve the
situation of duplicate classes in the classloader?

Furthermore, I noticed that the ejb-plugin doesn't just put the EJB
interfaces in the client package.  By default it puts any Bean inner
classes as well as utility classes, etc.  I realize that I can manually
configure the plugin to specify exactly which classes to include or
exclude, but that seems like it is not following the maven conventions over
configuration principles.

What are the best practices and approaches for using EJBs with Maven?  What
is the best way to build a WAR/EAR with Maven?

Thanks,

Eric