Eclipse的java程式碼出錯:The import org.apache cannot be resolved
【問題】
Eclipse中,折騰java程式碼。
把之前在android中的程式碼拿過來使用。
結果出現The import org.apache cannot be resolved的錯誤:
【解決過程】
1.這裡:
和
都說到了,讓去:
project -> Build Path -> Configure Build Path -> Libraries -> Add External Jar’s |
但是坑爹的卻是,沒有說,此處的
org.apache
是屬於哪個jar包。
2.既然找不到
org.apache
那麼,鑑於我此處,全部都是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import
org.apache.http.HttpEntity;
import
org.apache.http.HttpResponse;
import
org.apache.http.HttpStatus;
import
org.apache.http.NameValuePair;
import
org.apache.http.client.ClientProtocolException; import
org.apache.http.client.CookieStore;
//import
org.apache.http.client.HttpClient;
import
org.apache.http.client.entity.UrlEncodedFormEntity;
import
org.apache.http.client.methods.HttpGet;
import
org.apache.http.client.methods.HttpPost;
import
org.apache.http.client.methods.HttpUriRequest; import
org.apache.http.cookie.Cookie;
import
org.apache.http.impl.client.BasicCookieStore;
import
org.apache.http.impl.client.DefaultHttpClient;
//import
org.apache.http.impl.cookie.BasicClientCookie;
import
org.apache.http.params.HttpParams;
import
org.apache.http.protocol.BasicHttpContext;
import
org.apache.http.protocol.HttpContext;
import
org.apache.http.client.params.ClientPNames;
import
org.apache.http.client.protocol.ClientContext;
import
org.apache.http.util.EntityUtils;
|
即,全都是:
org.apache.http
那就先去找org.apache.http。
3.參考:
突然想到,貌似這個:
org.apache.http
是對應的android裡面的,不是標準的java庫中的。
4.所以,去到別人說的,apache官網中找這個庫。
搜:
download org.apache.http
解壓後,得到:
httpcomponents-client-4.2.5-bin\httpcomponents-client-4.2.5\lib
下面有很多jar:
先加進來試試:
然後所有的org.apache.http就正常了:
【總結】
org.apache,不是標準的java中的庫。所以eclipse中,無法自動識別。
org.apache下包括了一堆相關的庫,此處用到的的是org.apache.http,所以:
需要找到對應的org.apache.http相關的jar包,然後加到當前的專案中。
1.到哪裡找org.apache.http
去apache官網中的:
去下載:
即可,下載後,解壓,可以在:
httpcomponents-client-4.2.5-bin\httpcomponents-client-4.2.5\lib |
中看到對應的各個jar包:
commons-codec-1.6.jar fluent-hc-4.2.5.jar httpclient-4.2.5.jar httpclient-cache-4.2.5.jar httpcore-4.2.4.jar httpmime-4.2.5.jar |