java.lang.ClassNotFoundException:运行时com.mysql.jdbc.Driver(eclipse/maven/tomcat) [英] java.lang.ClassNotFoundException: com.mysql.jdbc.Driver during Runtime (eclipse / maven /tomcat)

查看:100
本文介绍了java.lang.ClassNotFoundException:运行时com.mysql.jdbc.Driver(eclipse/maven/tomcat)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行tomcat'java.lang.ClassNotFoundException:com.mysql.jdbc.Driver'时出现此错误.我正在使用Eclipse(Indigo,J2EE版本)/Maven(m2e-wtp)/Tomcat 7.0的组合.我已经在我的Web应用程序的pom文件中包含了这种依赖关系(从头开始构建).

I'm getting this error while running tomcat 'java.lang.ClassNotFoundException: com.mysql.jdbc.Driver'. I'm using a combination of Eclipse (Indigo, J2EE version) / Maven (m2e-wtp) / Tomcat 7.0. I've included this dependency in my pom file for my web application (build from scratch).

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>

在问题"视图中没有得到任何编译错误,但是当我从服务器"视图中运行Tomcat服务器时,出现了这些错误.它清楚地表明Tomcat无法找到Class,这是classpath配置错误,我希望Maven能够解决这个问题.

I do not get any compilation errors in the 'Problems' view but when I run the Tomcat server from the 'Servers' view, I get these errors. It clearly indicates that Tomcat is unable to find the Class and it is classpath configuration error and I was hoping that maven would take care of this.

我查看了与'java.lang.ClassNotFoundException:com.mysql.jdbc.Driver'相关的其他问题,但没有太大帮助.

I looked at other issues related to 'java.lang.ClassNotFoundException: com.mysql.jdbc.Driver' but weren't of much help.

我将不胜感激.

/**这就是我加载驱动程序的方式*/

/** This is how I load the Driver */

static {
        DriverAdapterCPDS cpds_Customer = new DriverAdapterCPDS();
        try {                        cpds_Customer.setDriver(productConfig.getProperty("dbcp.connection.customer.driver_class"));

        } catch (ClassNotFoundException e) {
            // log.error("setDriver Exception " + e);
            e.printStackTrace();
        }
               }

推荐答案

Tomcat 7要求JDBC驱动程序JAR必须进入其/lib目录:

Tomcat 7 requires that JDBC driver JARs must go in its /lib directory:

http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html

搜索忘记"一词.

这篇关于java.lang.ClassNotFoundException:运行时com.mysql.jdbc.Driver(eclipse/maven/tomcat)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆