Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » Problem with the Apache DefaultHttpClient class(Getting a java.lang.ClassNotFoundException for DefaultHttpClient)
Problem with the Apache DefaultHttpClient class [message #667555] Fri, 29 April 2011 14:07
Ahmet Ekrem SABAN is currently offline Ahmet Ekrem SABANFriend
Messages: 20
Registered: April 2011
Location: Austria
Junior Member

I am a newbie for servlet applications, trying to learn the subject. On my way, I wrote a servlet class called FormWebServlet that uses the org.apache.http.impl.client.DefaultHttpClient class. However, I get the exception

java.lang.ClassNotFoundException: org.apache.http.impl.client.DefaultHttpClient

... that clearly shows that this class does not exist, although I have added the jar file to the project.

The server returns an "HTTP Status 500" error with the message that the "root cause" is this missing class:

java.lang.NoClassDefFoundError: org/apache/http/impl/client/DefaultHttpClient

1) I searched for the missing jar file and added it to the project (by going on the project in "Eclipse JAVA EE IDE for Web Developers, 20100917-0705"'s project explorer, select "Properties", selected the "Java Build Path" and clicked the [Add External JARs...] button.) The added jar file is from the Apache site and is called httpclient-4.1.1.jar.
2) As I still get the same error, I extracted with 7-ZIP the DefaultHttpClient.class file and put it into the WebContent/WEB-INF/lib directory.

What am I doing wrong?

Notice: If I comment the definition of

HttpClient client = new DefaultHttpClient();

... and try to declare an HttpGet object instead with

			final String ADDRESS = ServletUtilities.getHttpAddress(BAR_CODE);

			out.println("ADDRESS = \"" + ADDRESS + '\"');
			HttpGet get = new HttpGet(ADDRESS);

... I get the same error, but this time for the class HttpGet - both part of the same JAR file.

Inculded JARs:

package testPackage;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import coreServlets.ServletUtilities;

@WebServlet(description = "Gets the book's barcode with a form", urlPatterns = { "/FormWebServlet" })
public class FormWebServlet extends HttpServlet {

	/** */
	private static final long serialVersionUID = 6008315960327824633L;

	 * @see HttpServlet#doGet(HttpServletRequest request,
	 *  HttpServletResponse response)
	protected void doGet(final HttpServletRequest request, 
			final HttpServletResponse response)
	throws IOException, ServletException {
		final String BAR_CODE = request.getParameter("barCode");

		final PrintWriter out = response.getWriter();

		if (BAR_CODE != null) {
			HttpClient client = new DefaultHttpClient();
			final String ADDRESS = ServletUtilities.getHttpAddress(BAR_CODE);

			out.println("ADDRESS = \"" + ADDRESS + '\"');
			HttpGet get = new HttpGet(ADDRESS);
			HttpResponse httpResponse = null;

// Removed commented code that will use these objects

Best regards!
Previous Topic:User code folding
Next Topic:My PDT problem
Goto Forum:

Current Time: Wed Jun 20 15:41:38 GMT 2018

Powered by FUDForum. Page generated in 0.01785 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top