2

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. enter image description here

coure2011
  • 40,286
  • 83
  • 216
  • 349

2 Answers2

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.

Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
  • how to add a jar file to build path? – coure2011 Oct 17 '12 at 11:09
  • @coure2011 See these links: - http://plugins.netbeans.org/plugin/11451/addtolibrary and http://stackoverflow.com/questions/4879903/how-to-add-a-jar-in-netbeans – Rohit Jain Oct 17 '12 at 11:14
  • @coure2011 You need to create a `lib` folder under your Project directory, and add all the Jar files in that folder. – Rohit Jain Oct 17 '12 at 11:15
  • Only doing that will not help, he needs to import the jars in his build path from lib dir – The Dark Knight Oct 17 '12 at 11:16
  • @TheDarkKnight Yeah that's what the links I gave tells. I gave to him so that he can understand it better.. – Rohit Jain Oct 17 '12 at 11:19
  • what is "Import the jar in his build path"??? I found that javax.persistence is already showing in my Libraries folder in Netbeans – coure2011 Oct 17 '12 at 11:28
  • @coure2011 Go to the link I provided. It explains how to add the Jar files from lib folder to library.. `Right Click on your jar file -> Add to Library` – Rohit Jain Oct 17 '12 at 11:30
  • The jars may be present in your library folder, but that does not get them to your build path . For that do this : right click on project -> goto java build path -> Then click your lib folder of the project, it will show you the jars u have not added . Then add the jars and do a build . – The Dark Knight Oct 17 '12 at 11:30
  • It also added in build path see the screenshot and updated info for question – coure2011 Oct 17 '12 at 11:38
  • @coure2011 Well, can't see your screenshot in office. :( – Rohit Jain Oct 17 '12 at 11:40
0

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/

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Sathish
  • 4,403
  • 7
  • 31
  • 53
  • 1
    I don't think this is the right solution for Tomcat. You only need the JPA-API JAR file ... not all of the J2EE APIs. (You already have a lot of the J2EE APIs and implementation classes in Tomcat.) – Stephen C Oct 17 '12 at 11:45