GWT/Hibernate: java.lang.NoClassDefFoundError: org/hibernate/Interceptor

GWT/Hibernate: java.lang.NoClassDefFoundError: org/hibernate/Interceptor

我正在尝试在我的 project-web-server 中初始化一个 Hibernate 会话。为此,我正在使用我编写的 project-data-model 库,它在 maven 中作为依赖项链接:

项目网络服务器 pom.xml:

    <dependency>
        <groupId>com.preoject.server</groupId>
        <artifactId>project-data-model</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

HibernateSession.java 因此在 project-data-model 中;这就是我在 project-web-server:

中使用它的方式
public class ServerConfig implements ServletContextListener {

    public void contextInitialized(ServletContextEvent event) {
        try {
            HibernateSession.initialize();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void contextDestroyed(ServletContextEvent event) {
        // Do stuff on shutdown.
    }
}

尽管我将数据模型项目引用为依赖项,但我得到了一个 java.lang.NoClassDefFoundError 异常:

java.lang.NoClassDefFoundError: org/hibernate/Interceptor
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
    at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:65)
    at com.project.datamodel.HibernateSession.initialize(HibernateSession.java:19)
    at com.project.web.server.ServerConfig.contextInitialized(ServerConfig.java:14)
    ...

我不知道我必须在这里做什么。文件夹 war/WEB-INF/lib 不包含任何 Hibernate 相关的库;这可能是问题所在吗?我不确定,因为我已经将 Hibernate 依赖项添加到父 pom.xml:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.2.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.common</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>4.0.1.Final</version>
        <classifier>tests</classifier>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.0.1.Final</version>
    </dependency>

默认情况下,Maven Eclipse 插件会将您的依赖项添加到 Eclipse 项目类路径中。它不知道任何自定义 build/packaging/deployment 场景,除非您为您需要的用例明确配置它。也许这个 question can be helpful in your use case. This article 解释了如何配置 M2Eclipse 插件目标。

尽管如此,我希望 Eclipse 的 GWT 插件(我假设你使用它)从项目类路径中获取所有内容并将其复制到适当的位置,我不确定为什么它不对你的设置。