2012-08-29 28 views
9

解決以下org.apache包不能在Eclipse

import org.apache.http.HttpEntity; 
import org.apache.http.HttpResponse; 
import org.apache.http.StatusLine; 
import org.apache.http.client.ClientProtocolException; 
import org.apache.http.client.methods.HttpGet; 
import org.apache.http.impl.client.DefaultHttpClient; 

不能得到解決。我下載了Apache Http包並通過外部jar選項導入它們,但仍然無法解決。在Android中,似乎可以工作,猜測它在SDK中,但在這裏我沒有做Android。我收到了錯誤的包裹嗎?

我相信這是鏈接:

Apache

+2

有時在導入外部庫之後,我不得不刷新依賴關係或關閉並打開項目以使eclipse錯誤消失。 –

+0

好點。正因爲這個原因,我經常做一個Eclipse「Project,Clean」。 – paulsm4

回答

13

聽起來 OK:

1) The .jar file in question should be something like "httpcore-4.0.1.jar". 
    Please confirm the name. 

2) Adding this to "External Libraries" is absolutely the correct thing to do. 

3) For compiling in the Eclipse IDE, you must: 

    a) Select your project 

    b) Select "Build Path" > "Add External Libraries" 

4) For running in the Eclipse IDE, you must 

    a) Select "Run" > "Run configurations". 
     Choose your (Java Application?) configuration. 

    b) Select "Classpath" > "Add External Jar" 

5) For running outside of the Eclipse IDE, you must make sure the .jar 
    file is present and your -cp (Classpath) argument is set correctly. 
+2

謝謝paulsm4。谷歌刪除了對Apache HTTP Client的支持,根據這個:https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client 你自己必須從 下載httpcore-4.0.1.jar的副本http://www.java2s.com/Code/Jar/h/Downloadhttpcore401jar.htm 將其導入到libs文件夾中。這將解決問題。 Proguard例外: -dontwarn org.apache.http。** -dontwarn com.android.volley.toolbox。** –

0

如果你第一次添加這些JAR文件到Android項目,但現在想使用它們在另一個(非Android)項目中,確保您已將JAR導入到其他項目中。在Eclipse中,每個項目都維護自己的構建類路徑設置,因此將JAR導入到一個項目中並不會自動使其可用於其他項目。

+0

這不是我的意思。我只是說在Android的情況下,所有這些軟件包都可用,所以我不必導入各自的罐子 –

+0

@ E-Riz如果我想添加一個罐子,以便它可以用於所有項目,該怎麼辦,我必須將它添加到插件文件夾中 - C:\ eclipse-jee-luna-R-win32 \ eclipse \ plugins? – Nikhil

1

將罐子拖入我的項目後,我遇到了同樣的問題。

右鍵單擊該jar並選擇Build-path -> Add-to-Build-Path爲我工作。