[英]ClassNotFoundException for Eclipse project running a JBoss 7 server using C3P0
I have a project in Eclipse that uses a JBoss server.我在 Eclipse 中有一个使用 JBoss 服务器的项目。 I'm trying to change my database manager to use C3P0 .我正在尝试更改我的数据库管理器以使用C3P0 。 However, no matter what I've tried I can't seem to import the jar files correctly.但是,无论我尝试过什么,我似乎都无法正确导入 jar 文件。
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:这是我尝试引用 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.我知道我可能没有正确使用 c3p0,但我现在只是想解决未找到类的问题。
Here are the steps I took to import the jars:以下是我导入罐子的步骤:
My .classpath file has the following in it as a result:结果,我的 .classpath 文件中包含以下内容:
<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.它找不到 c3p0 类文件。 What am I doing wrong?我究竟做错了什么? Any help is much appreciated!任何帮助深表感谢!
所有提到的三个 jars 复制并放置在 jboss 的 common lib 文件夹中并尝试,它会工作。一旦它解决了这个问题,那么你可以检查类加载器问题。
You need to put these jars in WEB-INF/lib
folder OR add as Module in JBoss.您需要将这些 jars 放在WEB-INF/lib
文件夹中或在 JBoss 中作为模块添加。
Easier way is to add these jars in WEB-INF/lib
and try.更简单的方法是在WEB-INF/lib
添加这些 jars 并尝试。
just add this dependency in your pom.xml :只需在您的 pom.xml 中添加此依赖项:
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
after adding jar in web-inf/lib.在 web-inf/lib 中添加 jar 后。 build jars then do following step构建 jars 然后执行以下步骤
Right click on project ---> select "properties" --> Deployement assembly --> "ADD" option --> select "java build path entries" --> select path of c3p0 jar右键项目--->选择“属性”-->部署程序集-->“添加”选项-->选择“java构建路径条目”-->选择c3p0 jar的路径
**sandeep solanke **桑迪普索兰克
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.