我將Apache HttpClient 4.3.5 jar添加到我的項目中的新用戶庫,但是每當我運行我的程序時,都會收到NoClassDefFound運行時錯誤。我可以告訴這是由HttpClient類引起的。我不知道如何緩解這個問題。將HttpClient jar添加到eclipse
1
A
回答
1
NoClassDefFound通常表示您缺少對類路徑的所需依賴關係。
如果你看看Maven pom.xml for httpclient,你會發現它有一些傳遞性依賴關係,它的含義取決於其他工件。
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
所以你可以看到三個神器httpclient
取決於:httpcore
,commons-logging
和commons-codec
。
這就是說,你可能會錯過這些依賴關係(因此NoClassDefFound)。如果您使用的是Maven,當您將httpclient
作爲依賴項添加時,Maven會爲您提供這些傳遞依賴項int。
但是,它看起來並不像您使用的是Maven。所以你想要做的是下載整個包在HttpComponents Home Page。如果你抓住了二進制distrubutions,像4.3.5.zip,並解壓縮,你會看到在lib
DIR所有這些罐子:做的僅僅是添加所有這些罐子到一個庫
commons-codec-1.6
commons-logging-1.1.3
fluent-hc-4.3.5
httpclient-4.3.5
httpclient-cache-4.3.5
httpcore-4.3.2
httpmime-4.3.5
最好的事情。然後將所有該庫添加到您的項目。
- 簡單轉到[窗口] → [設置] →【JAVA] → [構建路徑] → [用戶庫]
- 選擇新並鍵入一個名稱
- 選擇新的圖書館,選擇添加外部罐子,瀏覽並添加您下載的
lib
目錄中的所有罐子。 - 將庫添加到您的項目中。
相關問題
- 1. 添加jar文檔到eclipse
- 2. 將JAR添加到Eclipse Java庫
- 3. 將jar添加到eclipse插件中
- 4. 將JAR添加到eclipse項目
- 5. 將jar添加到eclipse插件(hadoop)
- 6. 將jar添加到Eclipse插件
- 7. HttpClient-將CipherInputStream添加到MultipartEntity
- 8. 將Eclipse模塊添加到Eclipse中的JAR類路徑中
- 9. 將Eclipse文檔添加到Eclipse Project導出jar
- 10. 將Eclipse jar添加到Eclipse構建路徑
- 11. 添加jar庫到eclipse項目導出
- 12. 添加jar到Eclipse目標平臺
- 13. 外部jar添加到eclipse項目
- 14. 添加外部的jar到Eclipse RCP的
- 15. Android - 添加JAR文件到eclipse(hotpotato API)
- 16. 將jar添加到java webapp
- 17. 將Jsoup Jar添加到MapReduce
- 18. Eclipse:爲Jar添加資源
- 19. 將jar庫添加到jar文件中
- 20. 如何將jar庫添加到jar中
- 21. 如何將FormsAuthentication cookie添加到HttpClient HttpRequestMessage
- 22. 將非外部JAR添加到Eclipse Java項目
- 23. 如何將jar包添加到eclipse中的項目中?
- 24. 將圖像添加到Eclipse中的JAR文件?
- 25. 如何將外部jar添加到eclipse rcp應用程序中?
- 26. 在運行時將jar添加到Eclipse插件
- 27. 用相對路徑將jar文件添加到Eclipse項目中
- 28. 將一個類添加到現有的Jar文件 - Eclipse
- 29. 爲什麼我不能將.jar添加到eclipse git repo中?
- 30. 在eclipse中將外部jar添加到android項目中
你通過'Add external jars'添加了罐子? – venkatKA 2014-09-24 04:19:57
你如何準確地運行你的程序?在Eclipse中用'main()'方法右鍵單擊一個類並選擇'Run'?或者在命令行上? – Asaph 2014-09-24 04:20:31
如果你使用Eclipse,右鍵單擊項目,Build path-> Add external jar,選擇你httpclient jar並按ok! – Vito 2014-09-24 09:04:24