RichardMcK
RichardMcK

Reputation: 35

JPA functionality in a deployed WAR on Tomcat

I'm working on a project which aims to allow a user to add some film details to a database and displays the list of existing films. I have created a Dynamic Web Project in Eclipse using JPA to communicate with a remote database. All of this works fine when I run the project in the Eclipse IDE but when I export it to a WAR and deploy it on a Tomcat server the JPA functionality no longer works. The following error is thrown:

javax.servlet.ServletException: Servlet execution threw an exception
    servlets.AdminMenu.doGet(AdminMenu.java:31)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.NoClassDefFoundError: javax/persistence/Persistence
    servlets.DBOperator.getFilmList(DBOperator.java:22)
    servlets.AddFilm.doGet(AddFilm.java:28)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    servlets.AdminMenu.doGet(AdminMenu.java:31)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Do I need to package my persistence.xml etc. in a certain way before exporting and deploying?

Upvotes: 0

Views: 4739

Answers (1)

Joe
Joe

Reputation: 389

Most JPA libraries only come native to J2EE containers such as JBOSS, Glassfish, etc... Tomcat is a Servlet Container not a J2EE container. You would need to include the JPA implementation that you are seeking to use as a dependency and deploy it with your WAR.

Upvotes: 4

Related Questions