Reputation: 20591
I have a mavenized project, where I use JSR 303 (Bean validation). As reference implementation I use Hibernate-validator. In project I specified dependency:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.1.0.Final</version>
<scope>provided</scope>
</dependency>
With version 4.1.0 all works fine. But when I change it to 4.2.0. I get runtime error on this line:
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence
......//more stack-trace
java.lang.NoClassDefFoundError: Could not initialize class com.andr.myproject.services.utils.ValidationUtils
Where is problem?
UPD: Also I use Java-ee-5 dependency, not 6.
UPD2: this error occurs in JUnit test
Upvotes: 0
Views: 5409
Reputation: 19010
Do you happen to have the following dependency in your project:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
</dependency>
If so, you should make sure to exclude it from your runtime classpath, as this JAR can only be used for compilation but not at runtime (it's classes are modified so they contain no method implementations). You can use the API JAR provided by JBoss 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>
Likely adding Hibernate Core helped because it pulls in the JPA API in a separate JAR. You can find more information here.
Upvotes: 1
Reputation: 20591
I found solution:
I need to add hibernate-core dependency. Without it it wouldn't work.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.0.1.Final</version>
</dependency>
Upvotes: 0