0

I have a Maven project that uses Hibernate and PostgreSQL, and it's working fine on it's own. Now I want to use some classes from this project (essentially the database) in a servlet, but now things break.

I get a java.lang.NoClassDefFoundError: javax/persistence/Persistence error when accessing the servlet in Tomcat.

I'm thinking that somehow the Maven dependencies don't get "forwarded" to the servlet project, but I don't know what to do about it. I've added the Maven project to the servlet build path, and also to its "Web Deployment Assembly"... what more do I need to do?

Magnus
  • 17,157
  • 19
  • 104
  • 189
  • Possible duplicate of [java.lang.ClassNotFoundException: javax.persistence.Persistence cannot be found with JPA](http://stackoverflow.com/questions/25639515/java-lang-classnotfoundexception-javax-persistence-persistence-cannot-be-found) – Arpit Aggarwal Dec 08 '16 at 09:36

2 Answers2

0

Please try this dependency.

<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final-redhat-3</version>
</dependency>
Romeo
  • 129
  • 4
  • As I said, the dependencies are fine when running the Maven project alone, but for some reason they get screwed up when I'm using the project from a servlet project... – Magnus Dec 08 '16 at 09:31
0

1.Check for all the jars, make sure that all the dependencies are added.

2.Clean your tomcat

Try adding Runtime dependencies.

3.Right click on your project and select Properties-> Deployment Assembly

  • click on Add
  • select Java Build Path Entries
  • select Maven Dependencies
  • Finish

Re-run your server.

Hope this helps!!

karthik
  • 17
  • 2