你好我在控制台中有一些错误,我不知道它是什么意思,或者我使用了弃用的方法或者什么......我从未使用过这个jar org.apache.http
谢谢!
错误:
Exception in thread "main" 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 javaapplication1.JavaApplication1.main(JavaApplication1.java:31)
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:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
代码:
public class JavaApplication1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws JSONException, IOException {
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost("https://fcm.googleapis.com/fcm/send");
post.setHeader("Content-type", "application/json");
post.setHeader("Authorization", "key=...");
JSONObject message = new JSONObject();
message.put("to", "f_NnqnU8WiM:APA91bHRGGTCRJpc4UEr2zksJFuDyQM15ONAM368_RoelMrZaPI-2i-5nFjD8oFkUaqA_8pP1ij0j2TSzWPFmrfZ5J3lhnoJfC_QECWL3yr9puETwEff5sqshU6ROIV2ehzj9ULcSA3_");
message.put("priority", "high");
JSONObject notification = new JSONObject();
notification.put("title", "Koko");
notification.put("body", "Nouvelle invitation");
message.put("Notification", notification);
post.setEntity(new StringEntity(message.toString(), "UTF-8"));
HttpResponse response = client.execute(post);
}
}
答案 0 :(得分:1)
Apache httpclient 有一些依赖关系,包括Apache commons-logging 。
这些jar必须在运行时位于类路径中。
您可以在此处找到依赖项(请参阅“编译”部分):Project Dependencies。
如果你的项目使用一些管理依赖项的构建工具(比如Maven),这个页面也会帮助你: