Error: NoClassDefFoundError: org/apache/commons/logging/LogFactory
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.
Related videos on Youtube
JohnA
Updated on June 04, 2022Comments
-
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.
-
lexicore about 6 yearsTry adding
commons-logging
to your classpath. -
Rehan Azher about 6 yearsLooks like u are missing Apache Commons libs , please improt those. commons.apache.org/proper/commons-logging
-
VaL about 6 yearsDuplicate: stackoverflow.com/questions/1776415/…
-
DAIRAV about 6 yearspossible duplicate of stackoverflow.com/questions/1551697/…
-
Dan Rayson over 5 yearsI'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?!
-
-
JohnA about 6 yearsThank you. it's really strangely, because I have already try this, but now it's works. Thank you again.