我正在尝试使用 Apache DefaultHttpClient 来执行 JSON POST 请求,当我尝试实例化它时它给了我一个 NoClassDefFound 错误。
HttpClient client = new DefaultHttpClient();
我在构建路径中包含了以下 jars,
httpclient-4.2.5.jar httpcore-4.2-alpha2.jar json-simple-1.1.1.jar fluent-hc-4.2.5.jar httpclient-cache-4.2.5.jar httpmime-4.2.5.jar org. apache.httpcomponents.httpclient_4.2.5.jar
当我尝试如下导入 DefaultHttpClient 时我没有问题
import org.apache.http.impl.client.DefaultHttpClient;
但只有当我尝试像上面提到的那样做一个实例时。
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:187)
at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:146)
at AtlasService.main(AtlasService.java:53)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more