简体   繁体   中英

How to add external jar without Eclipse build path option?

My java file jdbc11.java was compiled successfully with javac jdbc11.java command in cmd, after that when I tried to to run java jdbc11 I got this exception:

java.lang.ClassNotFoundException: com.mysql.jdbc:Driver

refering to this code in the file

Class.forName("com.mysql.jdbc.Driver");

, when I tried it in eclipse ,I added to "Java Build Path" the external jar : mysql-connector-java-5.1.20-bin.jar and it run successfully . in case I didn't fix it with eclipse what should I done in the first try with java jdbc11 command in order to make work ? note: the jar in the same dir with the jdbc11.java

Try adding the mysql-connector jar to the classpath when you execute your command-line code:

java -cp mysql-connector-java-5.1.20-bin.jar;. jdbc11

http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/classpath.html

You have to add -classpath in the execute command

java -classpath mysql-connector-java-5.1.20-bin.jar jdbc11

如果我理解你就好了,你缺少的是java命令行中的-cp选项,如果你把它放在构建路径中,这就是eclispe在内部做的事情。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM