gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 07:47:38 26 4
gpt4 key购买 nike

我得到下一个错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.http.conn.ssl.DefaultHostnameVerifier.(DefaultHostnameVerifier.java:82) at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:955) at Main.main(Main.java:87) Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at java.net.URLClassLoader.findClass(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 more

我使用 intellij idea 并导入了 2 个库: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);

我几乎可以肯定问题出在库导入上,但我不确定也不知道如何解决。

最佳答案

请在您的项目中包含公共(public)日志记录 jar。可以从here下载

同样来自 Maven repository

关于java - 错误 : NoClassDefFoundError: org/apache/commons/logging/LogFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49646924/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com