获取java.lang.ClassNotFoundException

时间:2014-10-29 11:17:52

标签: java

我能够编译代码,但在运行时却抛出了未找到的类

C:\Users\Desktop\New>javac -classpath java-mail-1.4.4.jar SendMail.java

C:\Users\Desktop\New>java -classpath java-mail-1.4.4.jar SendMail

Exception in thread "main" java.lang.NoClassDefFoundError: SendMail
Caused by: java.lang.ClassNotFoundException: SendMail
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: SendMail.  Program will exit.

你能建议如何解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

尝试使用以下命令

编译java类

javac -classpath .;<jar file path>; Abc.java

执行java类

java -classpath .;<jar file path>; Abc

答案 1 :(得分:0)

尝试使用:

<强>窗

java -classpath java-mail-1.4.4.jar;. SendMail
                    note this  ----^