简体   繁体   中英

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

I am trying to initialize a Hibernate session in my project-web-server . For that I am using a library I wrote project-data-model that is linked as dependency in maven:

project-web-server pom.xml:

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

HibernateSession.java is therefore in project-data-model ; this is how I use it in 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.
    }
}

Even though I referenced the data model project as dependency I am getting a java.lang.NoClassDefFoundError exception:

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)
    ...

I can't figure out what I have to do here. The folder war/WEB-INF/lib does not contain any Hibernate related libraries; could that be the problem? I'm not sure because I have added the Hibernate dependencies to the parent 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 plugin will by default add your dependencies to the Eclipse project classpath. It is not aware of any custom build/packaging/deployment scenarios unless you explicitly configure it for the use cases you need. Maybe this question can be helpful in your use case. This article explains how to configure M2Eclipse plugin goals.

Nevertheless, I would expect GWT plugin for Eclipse (I assume you use it) to take everything from the project classpath and copy it to the appropriate places, I'm not sure why it doesn't do it with your setup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM