错误:NoClassDefFoundError:org / apache / commons / logging / LogFactory

问题描述 投票:2回答:3

我得到下一个错误:

线程“main”中的异常java.lang.NoClassDefFoundError:org.apache.http.conn.ssl.DefaultHostnameVerifier中的org / apache / commons / logging / LogFactory。(DefaultHostnameVerifier.java:82)位于org.apache.http.impl。 main.main(main.java:87)中的client.HttpClientBuilder.build(HttpClientBuilder.java:955)引起:java.net.URLClassLoader.findClass中的java.lang.ClassNotFoundException:org.apache.commons.logging.LogFactory URLClassLoader.java:381)at java.lang.ClassLoader.loadClass(ClassLoader.java:424)at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:338)at java.lang.ClassLoader.loadClass(ClassLoader.java) :357)......还有3个

我使用intellij idea并导入了两个库:httpclient-4.5.5.jar和httpcore-4.4.9.jar

我班上的所有图书馆:

import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;

和代码示例:

    String urlToSendRequest = Constants.HOST + Constants.URL;
    String targetDomain = Constants.DOMAIN;

    HttpClient httpClient = HttpClientBuilder.create().build();
    HttpHost targetHost = new HttpHost(targetDomain, 80, "http");

    HttpPost httpPost = new HttpPost(urlToSendRequest);

    httpPost.addHeader("SENDCODE", "UTF-8");
    //...

    StringEntity entity = new StringEntity(Constants.MSG, "UTF-8");
    entity.setContentType("application/xml");
    httpPost.setEntity(entity);

    HttpResponse response = httpClient.execute(httpPost);

我几乎可以肯定问题是库导入,但我不确定并且不知道如何修复它。

java apache apache-httpclient-4.x
3个回答
1
投票

请下载commons-logging jar文件并设置路径。

http://commons.apache.org/proper/commons-logging/download_logging.cgi


1
投票

请在项目中包含commons logging jar。可以从here下载

也来自Maven repository


1
投票

好像你缺少了commons-logging lib。

© www.soinside.com 2019 - 2024. All rights reserved.