[标题]:[原]命令行运行class文件出现NoClassDefFoundError
[时间]:2012-02-14
[摘要]:Java命令运行程序时出现java.lang.NoClassDefFoundError: org/apache/http/HttpEntity。
[关键字]: Java、package、Jar、运行、error、class-path、库、HttpClient
[文章编号]:暂无
[环境]: JDK 7.0
[作者]: Wintys (wintys@gmail.com)
[错误]:
运行命令行:
java NetLogin -cp .;commons-codec-1.4.jar;commons-logging-1.1.1.jar;httpclient-4.1.3.jar;httpclient-cache-4.1.3.jar;httpcore-4.1.4.jar;httpmime-4.1.3.jar
出现如下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpEntity
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpEntity
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
[原因&解决]:
被运行的程序编译正常通过,运行却出现了NoClassDefFoundError,不知道是哪里出错了。找了半天,发现编译程序的命令行有问题,-cp参数应放到类名前面来:
java -cp .;commons-codec-1.4.jar;commons-logging-1.1.1.jar;httpclient-4.1.3.jar;httpclient-cache-4.1.3.jar;httpcore-4.1.4.jar;httpmime-4.1.3.jar NetLogin
原创作品,转载请务必保持原文完整性并注明出处。
作者:wintys (wintys@gmail.com)
博客:http://www.blogjava.net/wintys
posted on 2012-02-14 16:03
天堂露珠 阅读(2125)
评论(0) 编辑 收藏 所属分类:
Error