java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource in IntelliJ while it works fine in Eclipse

I made a simple Java EE app, and I have a problem with connection to database. In eclipse everything works fine, but when I try the same in Intellij errors occur.

package db;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;

public class DbUtil {
private static DbUtil dbUtil;
private ComboPooledDataSource connectionPool;

private DbUtil() throws PropertyVetoException {
    connectionPool = new ComboPooledDataSource();
    connectionPool.setDriverClass("com.mysql.jdbc.Driver");
    connectionPool.setJdbcUrl("jdbc:mysql://localhost:3306/world");
    connectionPool.setUser("root");
    connectionPool.setPassword("root");

    connectionPool.setInitialPoolSize(5);
    connectionPool.setMinPoolSize(5);
    connectionPool.setMaxPoolSize(20);
    connectionPool.setAcquireIncrement(5);
    connectionPool.setMaxIdleTime(3600);
}

public Connection getConnection() throws SQLException {
    return connectionPool.getConnection();
}

public void close() {
    connectionPool.close();
}

public static DbUtil getInstance() {
    if (dbUtil == null) {
        try {
            dbUtil = new DbUtil();
        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }
    }
    return dbUtil;
}
  }

In project structure - > libraries I have: image

And the errors are:

java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/ComboPooledDataSource
java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource

It's been a long time, but I faced the same problem and this solution worked.

In project_name/web/WEB-INF/ create new folder named lib, copy .jars c3p0-0.9.5.2, c3p0-oracle-thin-extras-0.9.5.2, mchange-commons-java-0.2.11 then in Project View select lib folder and finally Add as liblary....


Just add this dependencies to pom file

    <dependency>
        <groupId>com.google.code.maven-play-plugin.com.mchange</groupId>
        <artifactId>c3p0-oracle-thin-extras</artifactId>
        <version>0.9.5</version>
    </dependency>

    <dependency>
        <groupId>com.mchange</groupId>
        <artifactId>mchange-commons-java</artifactId>
        <version>0.2.11</version>
    </dependency>

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

This may be because of the servlet config

bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"

Download the c3p0 jar of hibernate to the lib ad it to the jars

http://www.java2s.com/Code/Jar/c/Downloadc3p0090jar.htm