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:
- Downloaded c3p0 libraries from here: http://sourceforge.net/projects/c3p0/?source=dlp
- 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)
- Right-clicked on each jar in Eclipse and hit "Build Path > Add to Build Path".
- 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!