I'm new to this forum and also new to JPA / EJB.
我是这个论坛的新手,也是JPA / EJB的新手。
I'm trying to deploy a .war file containing a small application to a tomcat server. The application is using JTA to communicate with the Derby db.
我正在尝试将包含一个小应用程序的.war文件部署到tomcat服务器上。应用程序使用JTA与Derby数据库通信。
When I run and deploy the application from and eclipse top the tomcat server running in eclipse, everything works perfect, but when I export a .war file and try to browse the application it throws an java.lang.ClassNotFoundException: javax.persistence.PersistenceException.
当我在eclipse中运行和部署应用程序,并在eclipse上运行tomcat服务器时,一切都很完美,但是当我导出一个.war文件并尝试浏览应用程序时,它抛出了一个java.lang。ClassNotFoundException:javax.persistence.PersistenceException。
My persistence file looks like this:
我的持久性文件如下:
<?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>
and the error thrown looks like this:
抛出的错误是这样的:
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)
Has anyone encountered this before?
有人以前遇到过这种情况吗?
Best regards Henrik
Henrik问好
2 个解决方案
#1
7
You seem to be missing the javax.persistence.PersistenceException class (part of the JPA spec).
您似乎忽略了java .persistence。PersistenceException类(JPA规范的一部分)。
The Java Persistence API JAR (containing the PersistenceException class) can be found here :
Java持久性API JAR(包含PersistenceException类)可以在这里找到:
http://repo1.maven.org/maven2/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar
http://repo1.maven.org/maven2/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar
This JAR needs to be in your WEB-INF/lib folder.
这个JAR需要放在您的WEB-INF/lib文件夹中。
Depending on how you've setup your Eclipse, it probably pushed these JARs to Tomcat automatically (by defining a library).
根据您如何设置Eclipse,它可能会自动地将这些jar推送到Tomcat(通过定义一个库)。
However, the fact that it tries to load the PersistenceException most likely means that another exception (the real exception) will occur once you solve this ClassNotFoundException.
然而,它试图加载PersistenceException的事实很可能意味着,一旦您解决了这个ClassNotFoundException,就会出现另一个异常(真正的异常)。
#2
0
If you are using Maven for managing project dependencies, then including the following in my pom.xml
worked for me:
如果您正在使用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>
#1
7
You seem to be missing the javax.persistence.PersistenceException class (part of the JPA spec).
您似乎忽略了java .persistence。PersistenceException类(JPA规范的一部分)。
The Java Persistence API JAR (containing the PersistenceException class) can be found here :
Java持久性API JAR(包含PersistenceException类)可以在这里找到:
http://repo1.maven.org/maven2/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar
http://repo1.maven.org/maven2/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar
This JAR needs to be in your WEB-INF/lib folder.
这个JAR需要放在您的WEB-INF/lib文件夹中。
Depending on how you've setup your Eclipse, it probably pushed these JARs to Tomcat automatically (by defining a library).
根据您如何设置Eclipse,它可能会自动地将这些jar推送到Tomcat(通过定义一个库)。
However, the fact that it tries to load the PersistenceException most likely means that another exception (the real exception) will occur once you solve this ClassNotFoundException.
然而,它试图加载PersistenceException的事实很可能意味着,一旦您解决了这个ClassNotFoundException,就会出现另一个异常(真正的异常)。
#2
0
If you are using Maven for managing project dependencies, then including the following in my pom.xml
worked for me:
如果您正在使用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>