August 19, 2009

Bundle a Common Jar Into EJB Jar with Maven Plugin maven-ejb-plugin

Yesterday I had some problem with packing an EJB3 jar with Maven plugin maven-ejb-plugin. The problem seemed quite common. To bundle a common jar dependency into an EJB jar, but after reading the documentation for the maven-ejb-plugin at, it seemed clear that the plugin lacked this capability. After several hour of failure I ran into a workaround . Instead of configure the maven-ejb-plugin I used the maven-dependency-plugin to copy the desired dependency jar into the target/classes directory and then configure maven-dependency-plugin to run before the package phase.

And if you need to add the common.jar to the classpath in the MANIFEST file add the following configuration to maven-ejb-plugin.


fedor_bel said...

Thanks alot, Pal!!!

That is exactly what I have been looking for!

I am a newbie in Maven and tryed to achieve the exactly same task! I just wanted to make that stupid maven include the damn jar into resulting jar as a dependency or something.

I spend entire day looking for a solution, I have read almost all the documentation for maven - so much bullshit! and nothing that answered such a simple and commonly asked question! I am sure the question is VERY common - because MAVEN is about dependencies! Well it excels in managing dependencies at build time. But what about run-time? Did they forget about it? That is exactly the issue we have here.

Well adding a working biuld-time dependency is as simple as adding a "dependency" in POM.

But how to achieve that same result for run-time? This is the next logical question for every normal person out there, trying to make his code to RUN after such an easy and successful build.

Thank you once again!

Anonymous said...

I've been googling for hours to find anything helpful on this topic. Not to mention the hours I've spent trying to solve it myself.

Thanks man!!!

Luc Bui said...
This comment has been removed by the author.
Magnus K Karlsson said...

A good reference article from SUN can be found here:

Fritz said...

Thank you for the great help, but I have a small addtion.

The example to add the classpath to the manifest must be like this:



Anonymous said...

You can do this by configuration of maven-ejb-plugin. You need to add configuration to this plugin:




Anonymous said...

Hi everybody,

You don't need add common jar into an ejb jar, just add common jar in classpath of the manifest file, see example of the link


Luigi Fugaro said...

Thank you sir!
I just copied you plugin tag and putted under my build/plugins tag... and all went well!

Thanks again!

maddy said...

I done it by just paste the jar file in apache maven dependency the it automatically show the dependency that actually what i want....any way thanks