休眠 C3P0 - NoClassDefFoundError

Hibernate C3P0 - NoClassDefFoundError

当我在 Glassfish 上的 Struts 应用程序第一次查询时,出现这样的错误:

Severe: Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
Info: 2015-07-28 13:59:17 ERROR HibernateUtil:54 - Initial SessionFactory creation failed
java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
    at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:176)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:143)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:84)
    at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:459)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:91)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2833)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2829)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
    [...]

我已尝试使用 this article 解决此问题,但仍然出现同样的错误..

我用于 运行 这个应用程序的依赖项:

        <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>3.6.3.Final</version>
                <type>jar</type>
        </dependency>
        <!-- Hibernate c3p0 connection pool -->
        <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-c3p0</artifactId>
                <version>3.6.3.Final</version>
        </dependency>
        <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-tools</artifactId>
                <version>3.6.0.CR1</version>
        </dependency>
        <dependency>
                <groupId>com.mchange</groupId>
                <artifactId>mchange-commons-java</artifactId>
                <version>0.2.10</version>
        </dependency>
        <dependency>
                <groupId>c3p0</groupId>
                <artifactId>c3p0-oracle-thin-extras</artifactId>
                <version>0.9.0.2</version>
        </dependency>
        <dependency>
                <groupId>com.mchange AND c3p0</groupId>
                <artifactId>c3p0</artifactId>
                <version>0.9.2.1</version>
        </dependency>

这个应用程序在没有 Maven 的情况下运行完美..

感谢帮助! :)

问题已解决 - 我必须将 c3p0-[version].jar 添加到 domains/domain1/libs[下的 Glassfish libs 目录中=10=]

<dependency>
   <groupId>com.mchange AND c3p0</groupId>
   <artifactId>c3p0</artifactId>
   <version>0.9.2.1</version>
</dependency>

AND c3p0是多余的

应该是

<dependency>
   <groupId>com.mchange</groupId>
   <artifactId>c3p0</artifactId>
   <version>0.9.2.1</version>
</dependency>

或者更好的是,使用当前的生产版本

<dependency>
   <groupId>com.mchange</groupId>
   <artifactId>c3p0</artifactId>
   <version>0.9.5.1</version>
</dependency>