java.lang.ClassNotFoundException: com.mysql.jdbc.Driver when executing JAR

陌路散爱 提交于 2019-11-29 04:55:44
BalusC

In case of JARs, the -cp and -classpath arguments and the %CLASSPATH% environment variable are ignored. Instead, the classpath has to be specified in the Class-Path entry of JAR's own /META-INF/MANIFEST.MF file. It can be a path relative to the JAR itself. E.g. in the same folder or in a /lib subfolder.

The below example assumes the driver to be in the same folder as the JAR.

Class-Path: mysql-connector-java.jar

(make sure that the MANIFEST.MF file has a blank line at the end)

See also:

Install MySQL connector for JAVA

sudo apt-get install libmysql-java

Set classpath

export CLASSPATH=$CLASSPATH:/usr/share/java/mysql-connector-java.jar

Source: http://marksman.wordpress.com/2009/03/01/setting-up-mysqljdbc-driver-on-ubuntu/

No matter where it's compiled, it will run smoothly in the same JVM implementation.

All you have to do is to properly include a JDBC driver connector in your classpath. Try putting mysql-connector-java.jar into the same directory with your program.

If you unzip this jar file, does it contain com/mysql/jdbc/Driver.class? If not, try to download jdbc driver implementation from the mysql web-site.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!