我是这个论坛的新手,也是JPA / EJB的新手。
我正在尝试将包含小应用程序的.war文件部署到tomcat服务器。该应用程序正在使用JTA与Derby数据库进行通信。
当我运行并从eclipse顶部运行在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)
有没有人遇到过这个?
祝你好运 亨利克
答案 0 :(得分:7)
您似乎缺少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就会发生另一个异常(真正的异常)。
答案 1 :(得分:0)
如果您使用Maven来管理项目依赖项,那么在pom.xml
中为我提供以下内容:
<!-- https://mvnrepository.com/artifact/javax.persistence/persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>