I’m trying to unit test a simple EJBModule project under NetBeans 7.1, but I am receiving one warning and an initialization error. I’m using GlassFish version 3.1.1. I’m hoping someone is familiar with this type of issue and can give me some suggestions on how to resolve it.
In project one we have a remote interface like this:
@Remote
public interface CredentialEJBRemote {
//Stuff
}
Then in a second project we are implementing the interface like this:
@Stateless
@LocalBean
public class CredentialEJB implements CredentialEJBRemote {
//@Override stuff
}
And finally in the unit test I am doing this:
private static EJBContainer ec = EJBContainer.createEJBContainer();
private static Context ctx = ec.getContext();
CredentialEJBRemote instance = (CredentialEJBRemote)ctx.lookup("java:global/classes/CredentialEJB");
//Do stuff with instance
When I run the unit test I receive the warning and the error.
The warning is:
WARNING: multiple versions of ant detected in path for junit
jar:file:/C:/Program%20Files/NetBeans%207.1/java/ant/lib/ant.jar!/org/apache/tools/ant/Project.class
and jar:file:/C:/Program%20Files/glassfish3.1.1/glassfish/modules/ant.jar!/org/apache/tools/ant/Project.class
Followed by this error on the test case:
Testcase: initializationError(trefliq.persistence.CredentialEJBTest): Caused an ERROR
Absent Code attribute in method that is not native or abstract in class file javax/ejb/embeddable/EJBContainer
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ejb/embeddable/EJBContainer
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(
at java.lang.ClassLoader.defineClass(ClassLoader.java:791) ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2308)
at java.lang.Class.getDeclaredFields(Class.java:1760)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
Any ideas what may be causing this?
Thanks so much.
This error turned out to be caused by having Netbean’s javaee-api-6.0.jar on the classpath. This jar does not contain the method bodies, so the elusive and seemingly rare “Absent code” error was being thrown. The Ant.jar warning was resolved by renaming the Ant.jar in GlassFish’s modules folder. It was conflicting Netbean’s Ant.jar because they are two different versions of Ant.