java.lang.ClassNotFoundException: javax.persistence.Entity Solution

(60 Views)


In this article, we are discussing the hibernate java.lang.ClassNotFoundException: javax.persistence.Entity, When you work on jpa project then this exception will occur very frequently,

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

Cause Of Exception

In JPA project, compiler is not able to find javax.persistence.Entity class as it is not included by default. It is stored in some jar which you have to include in your project to resolve this exception. Refer the solution below on how and what jar to add in your project to solve this issue.

Solution

javax.persistence.Entity class is present inside the J2EE SDK library "javaee.jar". You are missing this jar file in your project classpath.

You can add javaee.jar in your project by two ways:

  1. Using Maven
    <!-- https://mvnrepository.com/artifact/javax/javaee-api --> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency>
  2. J2EE SDK

    You can get the javaee.jar from Download javaee.jar

    Download the javaee.jar file from above link and include it in your classpath.

After Adding javaee.jar file to your project classpath, refresh and clean your project and then try running your application.

Solution Worked 1 UpvotesUpvote

        

Solution Didn't Worked 0 DownvotesDownvote



Comments



Search