Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

This is the recommended approach for people using OpenEJB for unit testing as it allows OpenEJB to find your application in the classpath without the need for you to specify any path information which tends to complicate builds.

openejb.xml file

An option is to use an openejb.xml file with your test case to point at directories OpenEJB should look for applications. One like the following would work fine:

...


<openejb>
    <Deployments dir="/path/to/my/appFoo" />
    <Deployments jar="/path/to/another/appBar.jar" />
</openejb>

Relative paths resolve to the openejb.base dir which defaults to the vm's user.dir system property when not set.

Including/Excluding paths (advanced)

...

The value of this property is a regular expression and therefore can be absolute or relative. For example the path "/Users/dblevins/work/swizzle/swizzle-stream/target/classes" which contains the class files of an application you wish to test could be included in any of the following values to the "openejb.deployments.classpath.include" property:

  • "file:///Users/dblevins/work/swizzle/swizzle-stream/target/classes/" (an absolute path)
  • "file:///Users/dblevins/work/swizzle/.*" (relative)
  • ".*swizzle-stream.*" (very relative)
  • ".*(swizzle-stream|swizzle-jira|acme-rocket-app).*" (including several paths)

Note the filtering is done on URLs in the classpath, so forward slashes should always be used even on OSs using backslash ("\").

...

The exclude and the include is applied separately and the results of each are combined together to create the list of paths OpenEJB will scrape for annotations.

Note by default these settings will only affect which jars OpenEJB will scan for annotated components when no descriptor is found. If you would like to use these settings to also filter out jars that do contain descriptors, set the openejb.deployments.classpath.filter.descriptors property to true. The default is false.

Troubleshooting

If you're having trouble determining if the META-INF/ejb-jar.xml file for your ejb module is in the classpath, a little debug code like this in your test setup will help you see what OpenEJB sees (which may be nothing):

Code Block

Enumeration<URL> ejbJars = this.getClass().getClassLoader().getResources("META-INF/ejb-jar.xml");
while (ejbJars.hasMoreElements()) {
    URL url = ejbJars.nextElement();
    System.out.println("app = " + url);
}