Eclipse中,折騰java代碼。
把之前在android中的代碼拿過來使用。
結果出現The import org.apache cannot be resolved的錯誤:
【解決過程】
1.這里:
求救,eclispe開發不能import org.apache 包
和
The import org.apache cannot be resolved
都說到了,讓去:
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
而找到http://hc.apache.org/downloads.cgi,去下載
HttpClient 4.2.5.zip
解壓后,得到:
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官網中的:
http://hc.apache.org/downloads.cgi
去下載:
HttpClient 4.2.5.zip
即可,下載后,解壓,可以在:
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 |
2.如何把jar加到當前項目
詳見:
http://www.crifan.com/java_eclipse_the_import_org_apache_cannot_be_resolved/