Problem

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


Caused by: java.lang.ClassNotFoundException: javax.transaction.TransactionManager
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)
… 23 more

Solution

The javax.transaction.TransactionManager 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.