[英]java.lang.NoClassDefFoundError: javax/persistence/Persistence
i'm using Netbeans 6.8 and build simple Maven web application project. 我正在使用Netbeans 6.8并构建简单的Maven Web应用程序项目。
create Entity and main file for persist Entity [also create persist unit] and use EclipsLink. 为持久化实体创建实体和主文件[也创建持久单元]并使用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 : 在netbeans项目窗口和我的项目库文件夹中只添加此包:
javaee-web-api-6.0.jar [provided] javaee-web-api-6.0.jar [提供]
please help me for solve this Error 请帮我解决这个错误
thanks 谢谢
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>
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. 另一个问题可能是您有一个项目导入另一个项目,父项目是应该拥有所有库的项目。
在您的pom.xml
您需要为JPA库添加依赖项。
This problems generally occures when there is no hibernate-jpa-2.0-api jar in classpath so first add this jar in your classpath. 当类路径中没有hibernate-jpa-2.0-api jar时,通常会出现此问题,因此首先在类路径中添加此jar。 if still you are getting excption then go to C:\\Users\\(system user name)\\.m2\\repository\\org\\hibernate; 如果你仍然得到了excption,那么转到C:\\ Users \\(系统用户名)\\。m2 \\ repository \\ org \\ hibernate; delete folder javax. 删除文件夹javax。 after that again download jars from pom.xml it will work. 之后再次从pom.xml下载jar它会起作用。
first make sure hibernate-jpa-2.0-api jar downloaded and it is available in your build path. 首先确保下载了hibernate-jpa-2.0-api jar,它在您的构建路径中可用。 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. 之后右键单击项目 - >构建路径--->配置构建路径--->部署程序集--->添加---> java构建路径条目--->选择可用的jar(hibernate-jpa- 2.0-API)--->下--->光洁度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.