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

By , 19 March 2012, 4:48 AM

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

Roger is an active member of the JSF 2 Expert Group and is happy to be a contributor to the Java Community. He has been writing software since the age of 8 and his other interests include languages, science, travel and surfing. You can follow Roger on Twitter and Google+.

Comment posted by: skylie, 3 months ago

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

Comment posted by: ivan, last week

 thanks man,
this has been of great help!

Add a comment

Please visit http://www.NinthAvenue.com.au/java-lang-classformaterror-exception-with-eclipselink-static-weaving-solved to add your comments.

Follow Ninth Avenue

Get Results With Women

Website Updates


Join The Mailing List

Subscribe to our mailing list for the latest news and announcements.

Follow Us On Twitter