Thursday, February 19, 2009

Using 3rd Party Libraries (JAR) from within an EJB.jar file...

Recently, people have been asking me how to include 3rd party libraries in the EAR file, so they don't have copy them to appServer/Domain lib director during deployment.

One way of doing this is include JARs in your EAR and reference them from the Manifest of your EJB.jar file. The steps are as follows:
  • Put the 3rd party JAR files in your EAR content (at the top level)
  • Edit your EJBs Manifest and update the "Class-path:" attribute to have a space (" ") separated list of the JAR names
  • Deploy your EAR to your appServer

The EAR should look like:
- EJB.jar
- 3rdpartyA.jar
- 3rdpartyB.jar

The EJB.jar's Manifest should look like:
Manifest-Version: 1.0
Class-Path: 3rdpartyA.jar 3rdpartyB.jar

Hope this helps - Thanks - Mark :-)