1

I have a project in Eclipse that uses a JBoss server. I'm trying to change my database manager to use C3P0. However, no matter what I've tried I can't seem to import the jar files correctly.

Here is the error I am getting:

javax.ejb.EJBException: Unexpected Error
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:157)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:213)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:284)
    ...
Caused by: java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/ComboPooledDataSource
    at com.softified.irw.common.DatabaseManager.<init>(DatabaseManager.java:24)
    at com.softified.irw.common.DatabaseManager.getDataSource(DatabaseManager.java:35)
    ...
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource from [Module "deployment.irw-ear.ear:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:361)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:333)
    ...

Here's a portion of my code that is trying to reference the jar:

import com.mchange.v2.c3p0.ComboPooledDataSource;


public class DatabaseManager {
    private static ComboPooledDataSource cpds = null;
    private static DataSource dataSource = null;
    private static Connection connection = null;
    private DatabaseManager(String clientName) {
        try {
            cpds = new ComboPooledDataSource();
            cpds.setDriverClass( "com.mysql.jdbc.Driver" ); //loads the jdbc driver
            cpds.setJdbcUrl("java:jboss/datasources/" + clientName+"DS");
        } catch (Exception e) {
            // Handle error that it's not configured in JNDI.
            throw new RuntimeException("Client "+clientName + " datasource configuration is missing in JNDI!", e);
        }
    }

I know I'm probably not using c3p0 right, but I'm just trying to get past the class not found issue right now.

Here are the steps I took to import the jars:

  1. Downloaded c3p0 libraries from here: http://sourceforge.net/projects/c3p0/?source=dlp
  2. Made a folder 'lib' in the project referencing the library and copied the following files into it from the c3p0 download:
    • c3p0-0.9.5-pre8.jar
    • mchange-commons-java-0.2.7.jar
    • c3p0-oracle-thin-extras-0.9.5-pre8.jar (I know I probably don't need this one, but I added it anyways)
  3. Right-clicked on each jar in Eclipse and hit "Build Path > Add to Build Path".
  4. All three jars now show up in my "References Libraries"

My .classpath file has the following in it as a result:

<classpathentry kind="lib" path="lib/c3p0-0.9.5-pre8.jar" sourcepath="lib/c3p0-0.9.5-pre8-sources.jar"/>
<classpathentry kind="lib" path="lib/c3p0-oracle-thin-extras-0.9.5-pre8.jar"/>
<classpathentry kind="lib" path="lib/mchange-commons-java-0.2.7.jar" sourcepath="lib/mchange-commons-java-0.2.7-sources.jar"/>

I keep getting that same error message when I try accessing the relevant part of my code. It can't find the c3p0 class files. What am I doing wrong? Any help is much appreciated!

Sunga
  • 309
  • 1
  • 4
  • 17

4 Answers4

0

All mentioned three jars copy and place inside the common lib folder of jboss and try, it will work.Once it will resolve this issue then you can check about class loader problem.

prashant thakre
  • 5,061
  • 3
  • 26
  • 39
0

You need to put these jars in WEB-INF/lib folder OR add as Module in JBoss.

Easier way is to add these jars in WEB-INF/lib and try.

James R. Perkins
  • 16,800
  • 44
  • 60
Neeraj
  • 327
  • 1
  • 8
  • I use JBoss AS 7, which I don't think supports just dropping the jars into a lib, so I'm trying to create a global module, but that is also somewhat confusing. – Sunga Aug 07 '14 at 15:01
  • That's not quite true. JBoss AS 7 will definitely support adding libraries to your `WEB-INF/lib` directory. – James R. Perkins Aug 07 '14 at 15:36
0

just add this dependency in your pom.xml :

<dependency>
    <groupId>c3p0</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.1.2</version>
</dependency>
Fakher
  • 2,098
  • 3
  • 29
  • 45
0

after adding jar in web-inf/lib. build jars then do following step

Right click on project ---> select "properties" --> Deployement assembly --> "ADD" option --> select "java build path entries" --> select path of c3p0 jar

**sandeep solanke