Sunday, July 28, 2013

exception in thread main java.lang.classformaterror: absent code attribute in method that is not native or abstract in class file javax/persistence/persistence


Problem

Maven project to run JPA stuff, using:

<dependency>
   <groupId>javax</groupId>
   <artifactId>javaee-api</artifactId>
   <version>6.0</version>
</dependency>


 Or:

<dependency>
   <groupId>javax</groupId>
   <artifactId>javaee-web-api</artifactId>
   <version>6.0</version>
</dependency>



Causes the following exception:

  Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence


Solution

Use an implementation jar, because the jars above are just compilation jars.
Instead see example below.

Why?

 This dependency provides you with the Java EE APIs, not the implementations.
 While this dependency works for compiling, it cannot be used for executing code (that includes tests).

See more at:
https://community.jboss.org/wiki/WhatsTheCauseOfThisExceptionJavalangClassFormatErrorAbsentCode


Example


No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...