Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problems with HTTPClient

807588Apr 8 2009 — edited Apr 8 2009
Hey guys. new to java and need some help to figure out what the problem here might be.
i am working in jdeveloper at the moment and have just succeeded to import my HTTPClient library and to test it i ran a tutorial code but it come upp with some errors.

code:
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;

import java.io.*;

public class HttpClientTutorial {

private static String url = "http://www.apache.org/";

public static void main(String[] args) {
// Create an instance of HttpClient.
HttpClient client = new HttpClient();

// Create a method instance.
GetMethod method = new GetMethod(url);

// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));

try {
// Execute the method.
int statusCode = client.executeMethod(method);

if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}

// Read the response body.
byte[] responseBody = method.getResponseBody();

// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
System.out.println(new String(responseBody));

} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
}
}

The error i get:
"C:\Program Files\jdev\jdk\bin\javaw.exe" -client -classpath "C:\Program Files\jdev\jdev\mywork\Test\Project1\classes;C:\Program Files\jdev\jdk\jre\lib\commons-httpclient-3.1\commons-httpclient-3.1.jar;C:\Program Files\jdev\jdk\jre\lib\commons-codec-1.3;C:\Program Files\jdev\jdk\jre\lib\commons-logging-1.1.1-src" HttpClientTutorial
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:66)
at HttpClientTutorial.main(HttpClientTutorial.java:13)
Process exited with exit code 1.

Anyone have an idea what the problem could be?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 6 2009
Added on Apr 8 2009
4 comments
609 views