HttpClient 无法处理 Tomcat、NoSuchMethodError org/apache/http/entity/ContentType

HttpClient no working on Tomcat, NoSuchMethodError org/apache/http/entity/ContentType

我使用 org.apache.http.client 从 Tomcat 调用 POST 7. 相同的代码在我的开发机器上工作,但在我的服务器上失败。

我似乎是类加载器的问题,但我仔细检查了所有的罐子,它们的 lib 目录中有相同的罐子。

java.lang.NoSuchMethodError: org.apache.http.entity.StringEntity.<init>(Ljava/lang/String;Lorg/apache/http/entity/ContentType;)V
    org.apache.http.client.entity.UrlEncodedFormEntity.<init>(UrlEncodedFormEntity.java:61)
    org.botlibre.util.Utils.httpPOST(Utils.java:424)

我转储了罐子,tomcat 都使用相同的 httpclient-4.2。5.jar 和 http 罐子。

我的开发机器有 tomcat 7.0.50,服务器有 7.0.68

CodeSource src = StringEntity.class.getProtectionDomain().getCodeSource();
if (src != null) {
  System.out.println(src.getLocation());
}
Class klass = StringEntity.class;
URL location = klass.getResource('/' + klass.getName().replace('.', '/') + ".class");
System.out.println(location);

好的,问题是我的其他 lib jar 中有另一个版本的 httpclient 类。出于某种原因,它在具有相同 jars 的开发机器上工作,我猜它以不同的顺序拾取它们。

我是这样调试的

Class klass = ContentType.class;
URL location = klass.getResource('/' + klass.getName().replace('.', '/') + ".class");
System.out.println(location);