-1

I found few posts related to this issue but none helped solve I am getting this error. I am using ant as a build tool. I tried different Jars like openjpa-persistence-1.2.1.jar, eclipselink-2.4.1, hibernate-jpa-2.0-api-1.0.1.Final-sources, and also used javaee-api-6.0.jar and put them into build path to see whether it finds the persistence.class body or not. but none helped. Any help is greatly appreciated.

Persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">

    <persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jar-file>lib/dependentProject.jar</jar-file>

    <properties>
            <property name="javax.persistence.validation.mode" value="none" />
            <property name="hibernate.archive.autodetection" value="class"/>
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
            <property name="hibernate.connection.username" value="XXX"/>
            <property name="hibernate.connection.password" value="XXX"/>
            <property name="hibernate.connection.url" value="connectionURL"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
        </properties>
    </persistence-unit>
</persistence>

Code that throws an error.

 EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit")

Error Msg:

Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Brijs001
  • 1
  • 2
  • Downvoted because image is provided instead of code. – SamHoque Dec 10 '18 at 18:53
  • As a note - there are a ton of existing questions on StackOverflow about ClassFormatError - [javadoc says](https://docs.oracle.com/javase/7/docs/api/java/lang/ClassFormatError.html) it's thrown when a class file and determines that the file is malformed or otherwise cannot be interpreted as a class file. – Krease Dec 10 '18 at 19:08
  • @krease I looked into the post you have mentioned but I am not using Maven. and I have a standalone app, it's not running on any server. – Brijs001 Dec 10 '18 at 19:21
  • @samzSakerz Code added – Brijs001 Dec 10 '18 at 19:30

1 Answers1

0

The problem is resolved. Actually I using Groovy and there was a version mismatch issue that somehow ended up giving me this error. I don't know exactly why. but as soon as I changed groovy plugin from 2.0 to 2.4 it solved this runtime error. Thanks.

Brijs001
  • 1
  • 2