java.lang.NoClassDefFoundError: javax/persistence/Persistence

痴心易碎 提交于 2019-11-28 05:10:55

问题


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


回答1:


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:)




回答2:


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>



回答3:


In your pom.xml you need to add a dependency to JPA libraries.




回答4:


Just incase you stumble upon this. Another problem could be you have a project importing another project the parent project is the one who is supposed to hold all the libraries.




回答5:


for maven quickstart artifacts:-

This problems generally occures when there is no hibernate-jpa-2.0-api jar in classpath so first add this jar in your classpath. if still you are getting excption then go to C:\Users\(system user name)\.m2\repository\org\hibernate; delete folder javax. after that again download jars from pom.xml it will work.

for webapp:--

first make sure hibernate-jpa-2.0-api jar downloaded and it is available in your build path. after that right click on project-->Build Path--->configure build path--->deployment Assembly--->Add--->java build path entries--->select the available jar(hibernate-jpa-2.0-api)--->next--->finish.



来源:https://stackoverflow.com/questions/2850850/java-lang-noclassdeffounderror-javax-persistence-persistence

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!