我是这个论坛的新手,也是JPA / EJB的新手。
我正在尝试将包含小型应用程序的.war文件部署到tomcat服务器。该应用程序正在使用JTA与Derby db通信。
当我从Eclipse上运行tomcat服务器并从其上运行和部署应用程序时,一切正常,但是当我导出.war文件并尝试浏览该应用程序时,它会抛出java.lang.ClassNotFoundException:javax.persistence.PersistenceException 。
我的持久性文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0">
<persistence-unit name="lab1" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<!--<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>-->
<class>entity.Team</class>
<class>entity.Gambler</class>
<class>entity.Bet</class>
<class>entity.Game</class>
<class>entity.Gameday</class>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:derby://localhost:1527/hean0901;create=true"/>
<property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="openjpa.ConnectionUserName" value="lab1"/>
<property name="openjpa.ConnectionPassword" value="user"/>
<property name="lab1.log" value="DefaultLevel=TRACE"/>
<property name="nonTransactionalDataSource" value="true"/>
<!-- <property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>-->
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" />
<property name="eclipselink.logging.level" value="FINEST"/>
</properties>
</persistence-unit>
</persistence>
和引发的错误看起来像这样:
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 1
1: <jsp:forward page="Setupcheck.do" />
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
javax.servlet.ServletException: Servlet execution threw an exception
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:706)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:677)
org.apache.jsp.index_jsp._jspService(index_jsp.java:54)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.NoClassDefFoundError: javax/persistence/PersistenceException
model.Setupcheck.processRequest(Setupcheck.java:31)
model.Setupcheck.doGet(Setupcheck.java:43)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:706)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:677)
org.apache.jsp.index_jsp._jspService(index_jsp.java:54)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.ClassNotFoundException: javax.persistence.PersistenceException
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
model.Setupcheck.processRequest(Setupcheck.java:31)
model.Setupcheck.doGet(Setupcheck.java:43)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:706)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:677)
org.apache.jsp.index_jsp._jspService(index_jsp.java:54)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
有人遇到过吗?
最好的祝福
亨里克
最佳答案
您似乎缺少了javax.persistence.PersistenceException类(JPA规范的一部分)。
您可以在以下位置找到Java Persistence API JAR(包含PersistenceException类):
http://repo1.maven.org/maven2/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar
该JAR必须位于您的WEB-INF / lib文件夹中。
根据您设置Eclipse的方式,它可能会自动(通过定义一个库)将这些JAR推送到Tomcat。
但是,它尝试加载PersistenceException的事实很可能意味着一旦解决此ClassNotFoundException,就会发生另一个异常(真正的异常)。