「已注销」
2016-07-18 03:56
采纳率: 80%
浏览 3.0k
已采纳

帮忙看看java的httpClients报错

一句话简介httpClients:

 Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性(具体区别,日后我们再讨论),它不仅是客户端发送Http请求变得容易,而且也方便了开发人员测试接口(基于Http协议的),即提高了开发的效率,也方便提高代码的健壮性。

我的java se项目中引入的jar包有:

  • D:\WorkSpace\JDBC\lib\httpclient-4.5.1.jar
  • D:\WorkSpace\JDBC\lib\httpcore-4.4.3.jar 这两个jar包,java代码如下:
import org.apache.http.impl.client.*;

public class HelloHttpClient {
    public static void main(String[] args) {
        CloseableHttpClient httpclient = null;

        try{
            httpclient = HttpClients.createDefault();
        } catch(NoClassDefFoundError e){
            System.out.println("报错...");
            e.printStackTrace();
        }
    }
} 

报错如下:

报错...
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at org.apache.http.conn.ssl.DefaultHostnameVerifier.<init>(DefaultHostnameVerifier.java:70)
    at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:944)
    at org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:58)
    at com.shizongger.httpClents.HelloHttpClient.main(HelloHttpClient.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 4 more

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • llxiaoh 2016-07-18 04:11
    已采纳

    缺少commons-logging的jar包

    2 打赏 评论

相关推荐 更多相似问题