I'm new to this forum and also new to 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.
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.
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
You seem to be missing the javax.persistence.PersistenceException class (part of the JPA spec).
The Java Persistence API JAR (containing the PersistenceException class) can be found here :
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.
Depending on how you've setup your Eclipse, it probably pushed these JARs to Tomcat automatically (by defining a library).
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.
If you are using Maven for managing project dependencies, then including the following in my pom.xml
worked for me:
<!-- https://mvnrepository.com/artifact/javax.persistence/persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
来源:https://stackoverflow.com/questions/4541893/deployed-war-to-tomcat-cant-throws-java-lang-noclassdeffounderror-javax-persis