如何添加没有Eclipse构建路径选项的外部jar? [英] How to add external jar without Eclipse build path option?

查看:235
本文介绍了如何添加没有Eclipse构建路径选项的外部jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的java文件jdbc11.java已经在cmd中被编译成 javac jdbc11.java 命令,之后我试图运行 java jdbc11 我有这个例外:

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

参考文件中的此代码

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

,当我在eclipse中尝试,我添加到Java Build Path的外部jar: mysql-connector-java-5.1.20-bin.jar 并运行成功。
如果我没有修复它与eclipse我应该做什么在第一次尝试与 java jdbc11 命令为了使工作?
注意:与jdbc11.java相同的目录中的jar与

, 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

推荐答案

尝试将mysql-connector jar添加到执行命令行代码时的类路径:

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

这篇关于如何添加没有Eclipse构建路径选项的外部jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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