java.lang.ClassNotFoundException: javax.persistence.Entity

Problem

In JPA or Hibernate development, it hits the following error message :


Caused by: java.lang.ClassNotFoundException: javax.persistence.Entity
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 24 more

Solution

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

1. J2EE SDK

You can always get the javaee.jar from http://java.sun.com/javaee/. Download and install the SDK in your computer, the javaee.jar can be found in the “\J2EE_SDK_FOLDER\lib” folder. For example,


C:\Sun\SDK\lib\javaee.jar

Get the javaee.jar file and include it in your project classpath.

2. Java.Net Repository

Alternatively, you can get the “javaee.jar” from the java.net Maven


  <repositories>
  	<repository>
  		<id>Java.Net</id>
  		<url>http://download.java.net/maven/2/</url>
  	</repository>
  </repositories>
 
  <dependencies>
    <!-- Javaee API -->
	<dependency>
    	<groupId>javax</groupId>
    	<artifactId>javaee-api</artifactId>
    	<version>6.0</version>
	</dependency>
  </dependencies>
The downloaded java.net javaee.jar is not contains any method bodies, see this “how to get javaee.jar from Maven” article for detail.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Dave Whaley Recent comment authors
newest oldest most voted
Dave Whaley
Guest
Dave Whaley

For Java EE 6, I found javax.persistence.Entity in glassfish/modules/javax.persistence.jar