无法加载com.mysql.jdbc.Driver [英] Unable to load com.mysql.jdbc.Driver

查看:941
本文介绍了无法加载com.mysql.jdbc.Driver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的TestNG的应用程序运行Ant,我无法加载com.mysql.jdbc.Driver。

when I run ant for a Testng application, I am unable to load com.mysql.jdbc.Driver.

下面是抛出异常。

[testng] java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
[testng] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[testng] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[testng] at java.security.AccessController.doPrivileged(Native Method)

感谢和问候,
Sreekanth

Thanks and regards, Sreekanth

推荐答案

CLASSPATH 环境变量的使用的的java.exe 命令,甚至那么只有使用时的没有的任何 -cp -classpath -jar 参数。它的忽略按IDE的。

The CLASSPATH environment variable is only used by the java.exe command and even then only when used without any of the -cp, -classpath, -jar arguments. It is ignored by IDE's.

这是环境变量是在现实世界中也被认为是一个贫穷的做法,因为它打破了便携性。这只是有用的孙以prevent的首发厌倦了 -cp -classpath一次又一次输入相同的类路径参数。在现实世界中,批处理/ shell文件preferred。

That environment variable is in real world also considered a poor practice since it breaks portability. It's only "useful" for Sun to prevent that starters get tired of typing the same classpath again and again in the -cp or -classpath arguments. In real world, batch/shell files are preferred.

如果您使用的是IDE,类路径被称为构建路径(它重新presents 两个的编译时和运行时类路径)。您可以在项目的属性进行配置。您可以添加整个文件夹,您可以添加个人/外部JAR文件,您可以链接项目,等等。利用它。全忘了 CLASSPATH 环境变量。

If you're using an IDE, The classpath is called the "build path" (it represents both compiletime and runtime classpath). You can configure it in the project's properties. You can add a complete folder, you can add individual/external JAR files, you can link projects, etcetera. Make use of it. Forget the whole CLASSPATH environment variable.

有关命令提示符

您必须把完整路径jar文件在类路径(包括文件名):

You have to put the full path to the jarfile in the classpath (including the filename):

.;C:\j2sdk1.4.2_16\jre\lib;
C:\Program Files\mysql-connector-java-3.1.144\mysql-connector-java-3.1.14-bin.jar

由于河马说,你必须重新启动 CMD 改变,经过。如果它不工作,启动你的程序是这样的:

As Hippo said, you have to restart cmd after changing that. If it doesn't work, launch your program like this:

java -cp ".;C:\j2sdk1.4.2_16\jre\lib;
C:\Program Files\mysql-connector-java-3.1.144\mysql-connector-java-3.1.14-bin.jar"
my.class.Name

这篇关于无法加载com.mysql.jdbc.Driver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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