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

14,496

Solution 1

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

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

Solution 2

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

Also from Maven repository

Solution 3

Seems like you are missing commons-logging lib.

Share:
14,496

Related videos on Youtube

JohnA
Author by

JohnA

Updated on June 04, 2022

Comments

  • JohnA
    JohnA almost 2 years

    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.

  • JohnA
    JohnA about 6 years
    Thank you. it's really strangely, because I have already try this, but now it's works. Thank you again.