JohnA
JohnA

Reputation: 345

Error: NoClassDefFoundError: org/apache/commons/logging/LogFactory

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.

Upvotes: 5

Views: 23946

Answers (3)

doubleW
doubleW

Reputation: 688

Seems like you are missing commons-logging lib.

Upvotes: 2

DAIRAV
DAIRAV

Reputation: 731

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

Also from Maven repository

Upvotes: 2

shrikant
shrikant

Reputation: 441

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

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

Upvotes: 0

Related Questions