Skip to main content

Unit test initialization error

4 replies [Last post]
mrbhill
Offline
Joined: 2012-02-20
Points: 0

I am a student studying enterprise component architecture. I'm working on a simple EJB project, but I am running into issues with my unit tests. I'm using Netbeans 7.1 with Glassfish 3.1.1. I have a EJB Module project with a @Stateless @LocalBean that implements a @Remote interface from another project. In the unit test I am using an embedded EJB container, and attempt to do a lookup via the context.

The problem is I am getting the following warning:

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:/glassfish3/glassfish/modules/ant.jar!/org/apache/tools/ant/Project.class

And the following error:

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(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 java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.getDeclaredFields0(Native Method)

I am just wondering if anyone is familiar with this issue, and can perhaps give me some suggestions on how to resolve it?

Thank you for your time.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mvatkina
Offline
Joined: 2005-04-04
Points: 0

You are running into http://java.net/jira/browse/GLASSFISH-16285. It describes the workarounds.

-marina

mrbhill
Offline
Joined: 2012-02-20
Points: 0

Thanks for the reply, Marina.

Removing the Ant.jar from Glassfish got rid of the Ant warning. However, I am still getting the initialization error.

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(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)
Do you have any ideas? Thanks for your time.

mrbhill
Offline
Joined: 2012-02-20
Points: 0

I figured out the absent code error. The project that contained the remote interface had the javaee-api-6.0.jar on the classpath. I did not realize this was a problem until I removed it and the error immeadiately went away.

Thanks so much for the help.

adel.wafa2012
Offline
Joined: 2013-04-26
Points: 0

I got the same problem Mrbhill, i spent much time looking for a solution for that problem, So , please , if you still here , i will be grateful if you tells me the right solution to these problem