无法创建sessionFactory object.java.lang.NoClassDefFoundError:org / hibernate / cfg / Configuration

时间:2014-07-06 02:28:57

标签: java hibernate intellij-idea

我现在有这个例外:无法创建sessionFactory object.java.lang.NoClassDefFoundError:org / hibernate / cfg / Configuration 我正在使用Idea 12

hibernate.cfg.xml(在我的主包内):

<?xml version="1.0" encoding="utf-8"?>

    

    <!-- Database connection settings -->
    <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
    <property name="connection.url">jdbc:hsqldb:hsql://localhost/shop</property>
    <property name="connection.username">sa</property>
    <property name="connection.password"></property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.HSQLDialect</property>

    <!-- database pooling information -->
    <property name="connection_provider_class">org.hibernate.connection.C3P0ConnectionProvider
    </property>
    <property name="c3p0.minPoolSize">5</property>
    <property name="c3p0.timeout">1000</property>

    <!-- using container-managed JNDI
    <property name="hibernate.connection.datasource">
       java:comp/env/jdbc/LiveDataSource
    </property>   -->


    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>


    <property name="hibernate.hbm2ddl.auto">create</property>
    <!--<property name="hibernate.hbm2ddl.auto">create-drop</property>-->

    <mapping class="model.Admin"/>
    <mapping class="model.User"/>
    <mapping class="model.Address"/>
    <mapping class="model.Brand"/>
    <mapping class="model.Item"/>
    <mapping class="model.GenericItem"/>
    <mapping class="model.Size"/>
    <mapping class="model.Client"/>
    <mapping class="model.Order"/>

</session-factory>

这些是我的maven依赖项:

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd“&GT;     4.0.0

<groupId>shop</groupId>
<artifactId>shop</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>2.2.9</version>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
    <!--<dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
    </dependency>-->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.common</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>4.0.1.Final</version>
    </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-core</artifactId>
        <version>4.2.0.Final</version>
    </dependency>
    <dependency>
        <groupId>securityfilter</groupId>
        <artifactId>securityfilter</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>asm</groupId>
        <artifactId>asm-all</artifactId>
        <version>3.3.1</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>



</dependencies>

如果有帮助,这就是输出:

    [2014-07-13 08:11:48,631] Artifact shop:war exploded: Server is not connected. Deploy is not available.
jul 13, 2014 8:11:49 PM org.apache.catalina.core.AprLifecycleListener init
INFO: La biblioteca nativa de Apache Tomcat basada en ARP que permite un rendimiento ?ptimo en entornos de desarrollo no ha sido hallada en java.library.path: /Users/florenciavelarde/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
jul 13, 2014 8:11:49 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
jul 13, 2014 8:11:49 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
jul 13, 2014 8:11:49 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 711 ms
jul 13, 2014 8:11:49 PM org.apache.catalina.core.StandardService startInternal
INFO: Arrancando servicio Catalina
jul 13, 2014 8:11:49 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.39
jul 13, 2014 8:11:49 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
jul 13, 2014 8:11:49 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
jul 13, 2014 8:11:49 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 74 ms
Connected to server
[2014-07-13 08:11:50,049] Artifact shop:war exploded: Artifact is being deployed, please wait...
[2014-07-13 08:11:50,561] Artifact shop:war exploded: Artifact is deployed successfully
Failed to create sessionFactory object.java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

有谁知道如何解决这个问题?它所在的文件内容是否有问题?

1 个答案:

答案 0 :(得分:0)

如果SessionFactory收到此错误object.java.lang.NoClassDefFoundError,则表示您缺少hibernate库。

检查您的hibernate jar文件是否包含在类路径中。

所需的罐子是:

lib/antlr.jar
lib/cglib.jar
lib/asm.jar
lib/commons-collections.jar
lib/commons-logging.jar
lib/jta.jar
lib/dom4j.jar
lib/log4j.jar
lib/hibernate3.jar

顺便说一句,你也可以查看this post