如何将org.apache.http.legacy添加到sbt中

时间:2016-08-10 15:52:00

标签: java sbt apache-commons-httpclient

我正在使用apache httpclient,但找不到

import org.apache.http.impl.client.HttpClients;

快速搜索谷歌引导我到org.apache.http.legacy,但我找不到org.apache.http.legacy的组,工件和修订版

它们是什么以及如何将该依赖项添加到build.sbt文件中?总堆栈跟踪是

[error] /Users/vangapellisanthosh/Development/coupon-engine-play/app/utils/LocalUtils.java:13: cannot find symbol
[error]   symbol:   class HttpClients
[error]   location: package org.apache.http.impl.client
[error] import org.apache.http.impl.client.HttpClients;
[error] /Users/vangapellisanthosh/Development/coupon-engine-play/app/utils/LocalUtils.java:66: cannot find symbol
[error]   symbol:   variable HttpClients
[error]   location: class utils.LocalUtils
[error]         HttpClient httpclient = HttpClients.createDefault();
[info] /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java: /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java uses or overrides a deprecated API.
[info] /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java: Recompile with -Xlint:deprecation for details.
[error] (compile:compileIncremental) javac returned nonzero exit code
[info] Compiling 6 Scala sources and 18 Java sources to /Users/vangapellisanthosh/Development/coupon-engine-play/target/scala-2.11/classes...
[error] /Users/vangapellisanthosh/Development/coupon-engine-play/app/utils/LocalUtils.java:13: cannot find symbol
[error]   symbol:   class HttpClients
[error]   location: package org.apache.http.impl.client
[error] import org.apache.http.impl.client.HttpClients;
[error] /Users/vangapellisanthosh/Development/coupon-engine-play/app/utils/LocalUtils.java:66: cannot find symbol
[error]   symbol:   variable HttpClients
[error]   location: class utils.LocalUtils
[error]         HttpClient httpclient = HttpClients.createDefault();
[info] /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java: /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java uses or overrides a deprecated API.
[info] /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java: Recompile with -Xlint:deprecation for details.
[error] (compile:compileIncremental) javac returned nonzero exit code
[error] application - 

我的代码是

HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(URL);
httppost.addHeader(API_KEY, X_API_KEY);
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair(GRANT_TYPE, "password"));
params.add(new BasicNameValuePair(USERNAME, _USERNAME));
params.add(new BasicNameValuePair(PASSWORD, O_PASSWORD));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();

if (entity != null) {
    InputStream instream = entity.getContent();
    try {
        System.out.println(instream);
    } finally {
        instream.close();
    }
}

1 个答案:

答案 0 :(得分:2)

  

快速搜索谷歌引导我到org.apache.http.legacy

不确定您搜索的内容,但我知道这是用于Android项目的依赖项?

您正在寻找的内容可以在MvnRespository

找到
libraryDependencies += "org.apache.httpcomponents" % "httpclient" % "4.5.2"