2

i m using eclipse ide and when i run my program everything works fine but when i run the same program on server then it gives me this exception and i have already put my all far files as well as in my lib folder, Please help me to short out to this problem.

java.lang.ClassNotFoundException: org.apache.http.HttpRequest
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2836)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1160)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1668)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
    at org.controller.KeyRank.doPost(KeyRank.java:41)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

Here is my code :

   public String readGoogle(String keyword, int page) {
        HttpClient client = new DefaultHttpClient();  

        // Create a method instance
        keyword = keyword.trim();
        keyword = keyword.replaceAll(" ", "+");

        String url = "http://www.google.com/search?q="+keyword+"&start="+page+"&btnG=Google+Search&aq=f&oq=";
        String responseBody = "";
        HttpGet method = new HttpGet(url);  

        //Provide custom retry handler is necessary  
        //:OC:method.getParams().setParameter(HttpConnectionParams.RETRY_HANDLER, new DefaultHttpRequestRetryHandler(3, false));  


        try{  
        //execute the method  


            System.out.println("executing request " + method.getURI());  

            // Create a response handler  
            ResponseHandler responseHandler = new BasicResponseHandler();  
            responseBody = client.execute(method, responseHandler);  
            System.out.println("----------------------------------------");  
            System.out.println(responseBody);  
            System.out.println("----------------------------------------");  



            } 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();  

        }
        return responseBody;

    }
3
  • 1
    ClassNotFoundException can only mean that the specified class is not on your classpath. Check again that all the right jars are on your classpath. Commented Feb 26, 2013 at 19:00
  • yes i have already added all my jars as well as i have added jar to my WEB-INF/lib folder (httpclient-4.2.3.jar) but it's giving me exception same code working when i run it using main. but not working when i run it on localhost Commented Feb 26, 2013 at 19:03
  • @ashishchaudharyjavaoracle You need httpcore jar file. Check my answer below. Commented Feb 26, 2013 at 19:09

2 Answers 2

2

Add Http core jar to your build path, find the required jar from this url. http://www.java2s.com/Code/Jar/h/Downloadhttpcorejar.htm

deploy the jar and then compile, your error will be resolved.

Sign up to request clarification or add additional context in comments.

1 Comment

Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
1

Without your classpath configuration and knowledge about the web server you are deploying your application to, it is not easy to help but from the look of things, it seems you are missing the HttpCore jar in your deployment environment.

The missing class is found in that jar.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.