java.lang.ClassFormatError Exception With EclipseLink Static Weaving [SOLVED]

By , 19 March 2012

java.lang.ClassFormatError Exception With EclipseLink Static Weaving [SOLVED]
java.lang.ClassFormatError Exception With EclipseLink Static Weaving [SOLVED]

Here's an interesting exception that slapped me when I tried out using the EclipseLink static weaver on against a fresh Maven pom.xml for Java EE Web projects. The same exception occurs with the OpenJPA enhancer.

Executing tasks
     [java] Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/ValidationMode
     [java] 	at java.lang.ClassLoader.defineClass1(Native Method)
     [java] 	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
     [java] 	at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
     [java] 	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
     [java] 	at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
     [java] 	at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
     [java] 	at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
     [java] 	at java.security.AccessController.doPrivileged(Native Method)
     [java] 	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
     [java] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
     [java] 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
     [java] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
     [java] 	at org.apache.openjpa.persistence.PersistenceProductDerivation.configureBeanValidation(PersistenceProductDerivation.java:241)
     [java] 	at org.apache.openjpa.persistence.PersistenceProductDerivation.beforeConfigurationLoad(PersistenceProductDerivation.java:214)

It turns out this obscure error is because the default Java EE jars do not contain any actual code. To fix it, change your Java EE dependencies from

    <!-- Java EE libraries -->
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-web-api</artifactId>
      <version>6.0</version>
      <scope>provided</scope>
    </dependency>

to

    <!-- default Jave EE jars don't include code necessary fo
         bytecode enhancement so we use these instead -->
    <dependency>
      <groupId>org.jboss.spec</groupId>
      <artifactId>jboss-javaee-6.0</artifactId>
      <version>1.0.0.Final</version>
      <type>pom</type>
      <scope>provided</scope>
    </dependency>

You will also need to add the JBoss repository to your pom.xml if you aren't already using it:

  <repositories>
    <repository>
      <id>repository.jboss.org-public</id>
      <name>JBoss repository</name>
      <url>https://repository.jboss.org/nexus/content/groups/public</url>
    </repository>
  </repositories>
java.lang.ClassFormatError Exception With EclipseLink Static Weaving [SOLVED]

About Roger Keays

java.lang.ClassFormatError Exception With EclipseLink Static Weaving [SOLVED]

I guess I'd call myself a problem solver. Either that, or I'm some sort of organic machine designed to convert oxygen into carbon dioxide. You could go either way on that. I'm into languages and stuff. I wrote a book. It's okay, I guess. What else? I like reading, swimming, eating, and playing music. Satisfied? Sheesh.

Leave a Comment

Please visit https://rogerkeays.com/java-lang-classformaterror-exception-with-eclipselink-static-weaving-solved to add your comments.

Comment posted by: , 4 years ago

Not sure, but check what version of the Java EE jars you are compiling against. Maybe the ones in your build don't include code either.

Comment posted by: Usman, 4 years ago

I am having this java.lang.ClassFormatError Absent Code attribute can you help me to resolve this issue ..... i am not using maven.

Comment posted by: ivan, 4 years ago

 thanks man,
this has been of great help!

Comment posted by: skylie, 4 years ago

 good job! this was helpfull for me, thanks! :)