What's the header file for BasicHttpRequest
What's the header file for BasicHttpRequest? I am using Apache HttpComponents.
I'm trying to make a simple program, but I am getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.http.impl.client.AbstractHttpClient.(AbstractHttpClient.java:159) at org.apache.http.impl.client.DefaultHttpClient.(DefaultHttpClient.java:178) at test.mai开发者_JS百科n(test.java:24) Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
What is the header file for this line:
HttpRequest request = new BasicHttpRequest("GET", "/",HttpVersion.HTTP_1_1);
Java does not have "header files" like you have in C or C++. The error that you get is a runtime error (not a compile-time error), it doesn't have anything to do with a missing "header file".
Looking at the error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory ...
It complains that it cannot find the class org.apache.commons.logging.LogFactory
. The Apache HttpComponents library has a number of dependencies; one of them is Apache Commons Logging. You need to download that library and put the JAR file in your classpath.
Besides Commons Logging there are other dependencies. You have to make sure you have them all in your classpath. See this page: Dependencies for Apache HttpComponents
精彩评论