Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: javax/persistence/Persistence

i'm using Netbeans 6.8 and build simple Maven web application project.

create Entity and main file for persist Entity [also create persist unit] and use EclipsLink.

but when i run main file get this error :

Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/Persistence
        at Main.main(Main.java:34)
Caused by: java.lang.ClassNotFoundException: javax.persistence.Persistence
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        ... 1 more

in netbeans projects window and in my project libraries folder only add this package :

javaee-web-api-6.0.jar [provided]

please help me for solve this Error

thanks

like image 875
mehdi shahdoost Avatar asked Dec 09 '22 16:12

mehdi shahdoost


2 Answers

Click Here to download hibernate-jpa-2.0-api-1.0.1.Final.jar and put it into the project library, your application will work fine. Good luck:)

like image 138
Hunter Zhao Avatar answered Jan 01 '23 08:01

Hunter Zhao


I had the same problem and I solved it by changing the dependencies to the following :

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.jpa</artifactId>
        <version>2.7.3</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
like image 41
Francisco Fontes Avatar answered Jan 01 '23 06:01

Francisco Fontes