As of OpenEJB 3.1.1, you have the ability to specify an alternate set of deployment descriptors to use for a given environment. This is focused mostly on testing where it is often desirable to use a slightly different configuration a set of tests or even specific tests.
openejb.altdd.prefix
To use this functionality, just set the new "openejb.altdd.prefix" system property or InitialContext property to something like "test", then any descriptors in your META-INF/ directory that start with "test." will override the regular descriptor. So for example with an app like this:
- META-INF/ejb-jar.xml
- META-INF/test.ejb-jar.xml
- META-INF/persistence.xml
- META-INF/test.env-entry.properties
Just initialize your test case like so:
Properties properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); properties.setProperty("openejb.altdd.prefix", "test"); InitialContext initialContext = new InitialContext(properties);
The logical result will be the prefixed file replacing the non-prefixed file as the active descriptor:
- META-INF/ejb-jar.xml -> test.ejb-jar.xml
- META-INF/persistence.xml
- META-INF/env-entry.properties -> test.env-entry.properties
This will work in any environment in which OpenEJB works (embedded, standalone, tomcat, geronimo, etc.).
Note that there does not have to be an equivalent non-prefixed version of the file. In the example above, only a "test.env-entry.properties" file exists and there is no equivalent plain "env-entry.properties" file. This prefixing works for any deployment descriptor in the META-INF/ directory or WEB-INF/ directory. The prefix does not have to be "test" and could be anything you choose. You can also have as many prefixed files as you need and could even go as far as to have one prefix per individual test.