当我为 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)
谢谢和问候,斯里坎特
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.
该环境变量在现实世界中也被认为是一种糟糕的做法,因为它破坏了可移植性.对于 Sun 来说,防止初学者厌倦在 -cp 或 -classpath 参数中一遍又一遍地输入相同的类路径只是有用"的.在现实世界中,首选批处理/shell 文件.
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,则类路径称为构建路径"(它代表编译时和运行时类路径).您可以在项目的属性中对其进行配置.您可以添加一个完整的文件夹,您可以添加单个/外部 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.
对于命令提示符,
您必须将 jarfile 的完整路径放在类路径中(包括文件名):
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何有效地使用窗口函数根据 N 个先前值来决定How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函数根据
在“GROUP BY"中重用选择表达式的结果;条款reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用选择表达式的结果;条款?)
Pyspark DataFrameWriter jdbc 函数的 ignore 选项是忽略整Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函数的 ig
使用 INSERT INTO table ON DUPLICATE KEY 时出错,使用 Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 时出错,使用 for 循环数组
pyspark mysql jdbc load 调用 o23.load 时发生错误 没有合pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 调用 o23.load 时发生错误 没有合适的
如何将 Apache Spark 与 MySQL 集成以将数据库表作为How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何将 Apache Spark 与 MySQL 集成以将数据库表作为