JPA functionality in a deployed WAR on Tomcat

余生长醉 提交于 2021-02-04 21:43:06

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/28972937/jpa-functionality-in-a-deployed-war-on-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!