Application Libraries

Written by Joseph Ottinger

Sometimes it's required that your EJBs depend on external jar files, that you might not necessarily wish to expose to the entire application.

One way to do this in Orion is to add an extra library path to the .EAR deployment. The convention I've seen is to place extra jars in a lib dir (where lib is in the same location as the modules are, i.e., your application directory structure.) For example, our directory structure might look like this, in an .ear:

/                                     # top level
/myEjb.jar                      # my EJB
/myWeb.war                      # my web app
/META-INF/application.xml       # configuration file
/META-INF/orion-application.xml # orion config file
/lib/oscore.jar                 # the jar that the EJBs need
 

The key here is to tell Orion to include the files in lib in the classpath. They'll be searched before the EJBs will, so the EJBs will have access. In the orion-application.xml file, add the following line:

<library path="./lib" />
 

Consult the documentation on orion-application.xml if you're not sure exactly where this should be located.

Note that this approach will expose the jars in the lib directory to the entire application, including all ejb modules and web modules. 

Another way to do it, provided you're using 1.5.3 (or so) or later, is to specify an entry in the jar classpath of the EJB itself. This works for both packaged modules and exploded ones (ie, in a jar or in an open directory). Basically, the jar classpath is set via an entry in META-INF/MANIFEST.MF. Thus, the structure above could be reworked: instead of using orion-application.xml to set a classpath for the entire application, just add this line to the MANIFEST.MF of myEjb.jar:

Class-Path: lib/oscore.jar
 

This is, by the way, the normal and correct way to add external dependencies to jar files in java.

Copyright © 2007 IronFlare AB