i got a ClassNotFoundException with this code:
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
MySQL.connect();
I imported the mysql-connector ( http://dev.mysql.com/downloads/connector/j/5.0.html ) and added it in a special folder (I named it External) and added it to the build-path. When I launch it in Eclipse it works fine for me but if I export it as jar and launch it by java -jar it does not work to me and I get the ClassNotFoundException... Hope someone could help me :) Mabye it has to do something with the classpath but how do I edit it because -cp External/mysql-connector.jar does not work..
When you use java -jar
the -cp
option is ignored. See the tool documentation. You have to list the dependent JARs in the Class-path entry of the Manifest.
However the Class.forName()
line hasn't been needed since 2007.
我也认为您必须通过[-cp]配置导入的库,例如
java -cp ../lib/mysql-connector.jar;../lib/* ・・・
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.