I've used embedded glassfish in the following way:
public static void createContainer() throws IOException {
File target = new File("target/classes");
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(EJBContainer.MODULES, target);
properties.put("org.glassfish.ejb.embedded.glassfish.installation.root",
"/opt/glassfish3/glassfish");
container = EJBContainer.createEJBContainer(properties);
context = container.getContext();
}
@AfterSuite(alwaysRun = true)
public static void closeContainer() throws NamingException {
// close container
}
// I use this method to lookup
public static <T> T lookupBy(Class<T> type) {
try {
return (T) context.lookup("java:global/classes/" + type.getSimpleName());
} catch (NamingException ex) {
throw new RuntimeException(ex);
}
}
The problem is that embedded glassfish uses the classes in "target/classes" and maven cobertura uses "target/generated-classes/cobertura". Then, the first time the tests run it's ok, but in the second time, when cobertura run, I receive a java.lang.RuntimeException: javax.naming.NamingException (probably because cobertura is working on "target/generated-classes/cobertura" while glassfish is working on "target/classes").
Any ideas to solve this problem???