Tomcat + Eclipse Link + Vaadin,NoClassDefFoundError javax / persistence / Persistence

时间:2014-07-01 21:17:06

标签: eclipse tomcat hyperlink vaadin

我使用Vaadin和Eclipse Link作为基于MySQL数据库的Web应用程序。 我有一个以下类来管理数据库操作:

public class DatabaseManager {

    private static final String PERSISTENCE_UNIT_NAME = "students";
    private static EntityManagerFactory factory;
    private static EntityManager em;

    public DatabaseManager() {
        factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
        em = factory.createEntityManager();
    }

    public void addEntry(Student student) {

        em.getTransaction().begin();
        em.persist(student);
        em.getTransaction().commit();
    }
}

和以下persistence.xml文件:

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
  <persistence-unit name="students" transaction-type="RESOURCE_LOCAL">
  <class>com.example.simplegradebook.Student</class>
  <properties>
  <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
  <property name="javax.persistence.jdbc.url" value="jdbc:derby:C:\\Users\\Ja\\workspace\\SimpleDB;create=true" />
  <property name="javax.persistence.jdbc.user" value="test" />
  <property name="javax.persistence.jdbc.password" value="test" />

  <!-- EclipseLink should create the database schema automatically -->
  <!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> -->
  <property name="eclipselink.ddl-generation.output-mode" value="both" />
</properties>

 

我还有一个DBTest类,在其中我在控制台中测试DatabaseManager,一切似乎都没问题。但是当我举个例子时:

DatabaseManager dbm = new DatabaseManager();
dbm.addEntry(new Student(/*some stuff here*/));

在我的VaadinUI类中,我得到这样的错误:

com.vaadin.server.ServiceException: java.lang.NoClassDefFoundError:      javax/persistence/Persistence
com.vaadin.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1463)
com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1417)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:237)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

java.lang.NoClassDefFoundError: javax/persistence/Persistence
com.example.simplegradebook.DatabaseManager.<init>(DatabaseManager.java:19)
com.example.simplegradebook.SimplegradebookUI.init(SimplegradebookUI.java:44)
com.vaadin.ui.UI.doInit(UI.java:641)
com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:222)
com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74)
com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1405)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:237)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

我的项目中包含这些库:

javax.persistence_2.1.0.v201304241213.jar
javax.persistence.source_2.1.0.v201304241213.jar

任何可能导致问题的想法?

0 个答案:

没有答案