Java httpcomponents未按文件规定运行

Java httpcomponents未按文件规定运行,java,apache-httpclient-4.x,Java,Apache Httpclient 4.x,使用我在这里找到的代码:我创建了一个快速HTTP客户端应用程序。以下是一段代码片段: DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); log.info("Logging in"); HttpResponse response; try { response = httpclient.execute(httpGet); } catch (ClientProto

使用我在这里找到的代码:我创建了一个快速HTTP客户端应用程序。以下是一段代码片段:

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
log.info("Logging in");
HttpResponse response;
try {
  response = httpclient.execute(httpGet);
}
catch (ClientProtocolException cpe) {
  String msg = "Error logging in with:" + rootUrl;
  log.error(msg, cpe);
  throw new BusinessRuleException(msg, cpe);
}
catch (IOException ioe) {
  String msg = "Error logging in with:" + rootUrl;
  log.error(msg, ioe);
  throw new BusinessRuleException(msg, ioe);
}

try {
  System.out.println(response.getStatusLine());
  HttpEntity entity = response.getEntity();
  // do something useful with the response body
  // and ensure it is fully consumed
  EntityUtils.consume(entity);
}
catch (IOException ioe) {
  String msg = "Error retrieving login response:" + rootUrl;
  log.error(msg, ioe);
  throw new BusinessRuleException(msg, ioe);
}
finally {
  httpGet.releaseConnection();
}
我得到一个例外:

java.lang.NoSuchMethodError: org.apache.http.client.methods.HttpGet.releaseConnection()V
    at com.xerox.tclg.juror.schedule.RestScheduleRunner.runDailyCheckout(RestScheduleRunner.java:93)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:276)
    at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:260)
java.lang.NoSuchMethodError: org.apache.http.util.EntityUtils.consume(Lorg/apache/http/HttpEntity;)V
    at com.xerox.tclg.juror.schedule.RestScheduleRunner.runDailyCheckout(RestScheduleRunner.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:276)
    at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:260)
我发现一些文档说releaseConnection()是不必要的,所以我删除了finally块。然后我得到一个例外:

java.lang.NoSuchMethodError: org.apache.http.client.methods.HttpGet.releaseConnection()V
    at com.xerox.tclg.juror.schedule.RestScheduleRunner.runDailyCheckout(RestScheduleRunner.java:93)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:276)
    at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:260)
java.lang.NoSuchMethodError: org.apache.http.util.EntityUtils.consume(Lorg/apache/http/HttpEntity;)V
    at com.xerox.tclg.juror.schedule.RestScheduleRunner.runDailyCheckout(RestScheduleRunner.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:276)
    at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:260)

有人看到过吗?

在本例中,
java.lang.NoSuchMethodError
很可能意味着您获得了一个Http组件JAR文件的错误版本


如果您能够准确地了解“RestScheduleRunner.java:85”中发生的情况,它可能会帮助您诊断问题。

您确定运行应用程序时使用的HttpCore软件包与在IDE中开发和编译时使用的软件包相同吗?