0

Hello I have some error in the console, I don't know if what it meant or I used deprecated methods or something.. I have never used this jar org.apache.http

Thank you !

Errors :

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

Code :

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);
    }

}
Bibek Shakya
  • 1,233
  • 2
  • 23
  • 45
DionysoSong
  • 807
  • 1
  • 12
  • 29

1 Answers1

1

Apache httpclient has some dependencies , including Apache commons-logging.

These jars must be in the classpath at runtime.

You may find the dependencies here (see the "compile" section) : Project Dependencies .

If your project uses some build tool which manages dependencies (like Maven), this page will also help you :

Dependencies inforrmation

Arnaud
  • 17,229
  • 3
  • 31
  • 44