4

When I try to use c3p0 to test a mysql database connection, Eclipse shows the following error:

caused by:java.lang.NoClassDefFoundError:com/mchange/v2/ser/indirector,

I googled and was unable to find an answer.

Could anyone help me? I am a java rookie, thanks!

bjtitus
  • 4,231
  • 1
  • 27
  • 35
triven
  • 71
  • 1
  • 7
  • I don't understand what is c3p0. Could you add more details? – Prudhvi Mar 11 '15 at 02:01
  • c3p0 - JDBC3 Connection and Statement Pooling,details here http://www.mchange.com/projects/c3p0/ – triven Mar 11 '15 at 02:10
  • Go through this [question](http://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java), you might find it helpful. – Prudhvi Mar 11 '15 at 02:17

4 Answers4

5

First, make sure that your project is properly loading mchange-commons-java, where the stuff you are com.mchange.v2.ser.* lives. It is a transitive dependency of c3p0.

Hopefully you are using c3p0-0.9.5. Try changing the c3p0 config param contextClassLoaderSource to library to avoid some ClassLoader confusions.

Steve Waldman
  • 13,689
  • 1
  • 35
  • 45
2

I think you are only placing c3p0 jar in tomcat lib. If you copy mchange-commons-java jar also than this issue will be resolved.

Sandeep M
  • 248
  • 3
  • 6
0

I have the same problem. And I am using IntelliJ IDEA. Perhaps you can fix it by follow steps:

  • Add c3p0 and mchange-commons-java to your 'libs' folder and add them as 'Library';
  • Open 'File->Project Structure->Project Settings->Artifacts', then find c3p0-* and mchange-commons-java in
    the 'Available Elements', and 'Extract Into Output Root'.
  • Then build artifacts again.
beibeitu
  • 164
  • 7
0

In my case I was missing mchange-commons-java-0.2.11 (use your version) jar that contained the com/mchange/v2/ser/indirector class. We need this and c3p0-0.9.5.2 jars to be kept in app/WEB-INF/lib directory.

Just adding that worked!!!