通过命令行运行JAR时出错java.lang.ClassNotFoundException:com.mysql.jdbc.Driver [英] Error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver while running JAR through Command line

查看:197
本文介绍了通过命令行运行JAR时出错java.lang.ClassNotFoundException:com.mysql.jdbc.Driver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个java程序,我正在使用 mysql 数据库连接代码。
我添加了 mysql-connector-java-3.0.10-stable-bin.jar mysql-connector-java-5.0.4-bin.jar eclipse中我资源文件夹中的文件。
当我在Eclipse中运行程序时运行正常。
然后我创建了一个项目的 .jar 文件,其中包含该jar文件中的所有jar文件。
但是当我在DOS上运行带 java -jar myJar.jar 命令的 jar 文件时,它会给出错误 - java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

I have a java program in that I am using mysql database connectivity code. I have added mysql-connector-java-3.0.10-stable-bin.jar and mysql-connector-java-5.0.4-bin.jar files in my resource folder in eclipse. When I run the program in Eclipse it runs fine. Then I have created a .jar file of my project included all jar files in that jar file. But when I run my jar file with java -jar myJar.jar command on DOS prompt it gives the error - java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

我试过设置mysql-connector * .jar的CLASSPATH,但仍然得到同样的错误。
请帮我解决这个问题?

I tried with setting CLASSPATH of mysql-connector*.jar but still getting the same error. Please help me to resolve this problem?

提前致谢....

推荐答案

要解决此问题,您可以在Eclipse中创建 Runnable Jar文件而不是简单Jar文件

To resolve the problem you can create "Runnable Jar file" instead of "Simple Jar file" in Eclipse.

这篇关于通过命令行运行JAR时出错java.lang.ClassNotFoundException:com.mysql.jdbc.Driver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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