java.lang.ClassNotFoundException: javax.persistence.Entity

久未见 提交于 2020-01-04 13:01:13

问题


I got a sample project, copied from somewhere else, when I am trying to run it in netbeans I am getting some error/exceptions in tomcat's console window.

java.lang.ClassNotFoundException: javax.persistence.Entity
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
    at org.springframework.core.type.classreading.RecursiveAnnotationAttributesVisitor.visitEnd(AnnotationAttributesReadingVisitor.java:167)
    at org.springframework.asm.ClassReader.a(Unknown Source)
    at org.springframework.asm.ClassReader.accept(Unknown Source)
    at org.springframework.asm.ClassReader.accept(Unknown Source)

javax.persistence is already added to my project. I even removed and re-added in netbeans but still same error. This error is when running the web applictation not when compiling.


回答1:


You need to add following Jar Files to your Build Path: -

  • javax.persistence_2.0.3.v201010191057.jar
  • org.eclipse.persistence.jpa_2.3.0.v20110604-r9504.jar
  • org.eclipse.persistence.jpa.equinox_2.3.1.v20111018-r10243.jar
  • org.eclipse.persistence.antlr_2.3.0.v20110604-r9504.jar
  • org.eclipse.persistence.asm_2.3.0.v20110604-r9504.jar

Preferably adding the first one will work, as javax.persistence.Entity is found in that Jar only. But you may also need to add the later ones, for working with JPA

Google them with the name of JPA Jars. You will get them.




回答2:


The javax.persistence.Entity is a class inside the Java EE SDK library “javaee.jar“, you are missing this jar file in your project classpath.

refer this http://www.mkyong.com/hibernate/java-lang-classnotfoundexception-javax-persistence-entity/



来源:https://stackoverflow.com/questions/12932851/java-lang-classnotfoundexception-javax-persistence-entity

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