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