4
votes

I get next error:

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

I use intellij idea and imported 2 libs: httpclient-4.5.5.jar and httpcore-4.4.9.jar

All libs in my class:

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;

And code sample:

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

I'm almost sure that the problem is with libraries importing, but I'm not sure and have no idea how to fix it.

3
Try adding commons-logging to your classpath. - lexicore
Looks like u are missing Apache Commons libs , please improt those. commons.apache.org/proper/commons-logging - Rehan Azher
I'd love an answer that doesn't say "Then add it..." I CAN'T add it due to company policies here - what can I do?! - Dan Rayson

3 Answers

1
votes

please download the commons-logging jar file and set the path.

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

2
votes

Please include commons logging jar in your project. Can be downloaded from here

Also from Maven repository

1
votes

Seems like you are missing commons-logging lib.