Reputation: 29
I have a Java protect with the c3p0 JAR. Compiling my project in eclipse works. No errors or something. But when i try to run my application it says the following:
java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
Do i need to give the jar file the other jarfile from c3p0? Or could i link them when launging the application?
Upvotes: 1
Views: 225
Reputation: 75356
Note: I've understood your problem to be when running outside Eclipse.
The standard Java classloader responsible for loading your classes does not understand jar-files inside jar-files, so you need to do something else:
The File->Export->Runnable jar
option in Eclipse can do all three based on what you choose. Pick the one best suited to how you will get the classes to the final users.
Personally I like the "jars next to the generated jar" as it is the closest to what is supported out of the box by Java, while keeping the original jar files. The simplest is most likely to merge all classes, but when you get more advanced you will find that it has some disadvantages - at this point you will most likely not encounter them.
Upvotes: 2
Reputation: 5007
It looks like you did not added c3p0 in the classpath when you run the sample.
However you could use maven and m2e plugin for eclipse and add the following
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
beside the other dependencies you have.
after mvn eclipse: eclipse and you will have your project with a correct classpath.
Upvotes: 0