我构建了一个非常简单的测试程序,用于向具有XML有效负载的Web服务器提交HTTP Post。我包含jar
文件commons-httpclient-3.1.jar
,其中包含RequestEntity类,但是当我运行程序时,我收到以下错误,我无法确定无法找到该类的原因。
我的javac
命令:
javac -verbose -d classes -sourcepath src -cp lib\commons-httpclient-3.1.jar; src\testpartstorepost\PostXML2.java
详细输出显示它加载RequestEntity.class
[parsing started src\testpartstorepost\PostXML2.java]
[parsing completed 32ms]
[search path for source files: src]
[search path for class files: ***SNIP***
[loading java\io\File.class(java\io:File.class)]
[loading org\apache\commons\httpclient\HttpClient.class(org\apache\commons\httpclient:HttpClient.class)]
[loading org\apache\commons\httpclient\methods\FileRequestEntity.class(org\apache\commons\httpclient\methods:FileRequestEntity.class)]
[loading org\apache\commons\httpclient\methods\PostMethod.class(org\apache\commons\httpclient\methods:PostMethod.class)]
[loading org\apache\commons\httpclient\methods\RequestEntity.class(org\apache\commons\httpclient\methods:RequestEntity.class)]
[loading java\lang\Object.class(java\lang:Object.class)]
[loading java\lang\String.class(java\lang:String.class)]
[loading java\lang\Exception.class(java\lang:Exception.class)]
[checking testpartstorepost.PostXML2]
[loading java\lang\Throwable.class(java\lang:Throwable.class)]
[loading java\net\URI.class(java\net:URI.class)]
[loading org\apache\commons\httpclient\methods\EntityEnclosingMethod.class(org\apache\commons\httpclient\methods:EntityEnclosingMethod.class)]
[loading org\apache\commons\httpclient\methods\ExpectContinueMethod.class(org\apache\commons\httpclient\methods:ExpectContinueMethod.class)]
[loading org\apache\commons\httpclient\HttpMethodBase.class(org\apache\commons\httpclient:HttpMethodBase.class)]
[loading org\apache\commons\httpclient\HostConfiguration.class(org\apache\commons\httpclient:HostConfiguration.class)]
[loading org\apache\commons\httpclient\HttpMethod.class(org\apache\commons\httpclient:HttpMethod.class)]
[loading java\lang\System.class(java\lang:System.class)]
[loading java\io\PrintStream.class(java\io:PrintStream.class)]
[loading java\io\FilterOutputStream.class(java\io:FilterOutputStream.class)]
[loading java\io\OutputStream.class(java\io:OutputStream.class)]
[loading java\lang\Error.class(java\lang:Error.class)]
[loading java\io\IOException.class(java\io:IOException.class)]
[loading java\lang\RuntimeException.class(java\lang:RuntimeException.class)]
[loading org\apache\commons\httpclient\HttpException.class(org\apache\commons\httpclient:HttpException.class)]
[loading java\lang\StringBuilder.class(java\lang:StringBuilder.class)]
[loading java\lang\AbstractStringBuilder.class(java\lang:AbstractStringBuilder.class)]
[loading java\lang\CharSequence.class(java\lang:CharSequence.class)]
[loading java\io\Serializable.class(java\io:Serializable.class)]
[loading java\lang\Comparable.class(java\lang:Comparable.class)]
[loading java\lang\StringBuffer.class(java\lang:StringBuffer.class)]
[wrote classes\testpartstorepost\PostXML2.class]
但是当我运行该程序时,我得到以下内容:
D:\java testpartstorepost/PostXML2
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/methods/RequestEntity
Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.methods.RequestEntity
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: testpartstorepost/PostXML2. Program will exit.
如果需要,我也可以提供java源代码。我无法确定为什么程序找不到RequestEntity
修改
如果我将我的java调用更改为指向右侧classpath
,我会更进一步,请认为这个已经解决了。
java -cp .;..\lib\commons-httpclient-3.1.jar; testpartstorepost/PostXML2
答案 0 :(得分:1)
你确定你的类路径是正确的吗?它的相对路径,所以重要的是你启动javac的目录。