title: Unable to run search tweets using Twitter4j
body: <p>I was trying to display all the searched results into the webpage but was unable to do so.</p>
  
  <p>TwitterCrawlServlet.java</p>
  
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
          ConfigurationBuilder cb = new ConfigurationBuilder();
          cb.setDebugEnabled(true)
                .setOAuthConsumerKey("xxx")
                .setOAuthConsumerSecret("xxx")
                .setOAuthAccessToken("xxx")
                .setOAuthAccessTokenSecret("xxx");
          TwitterFactory tf = new TwitterFactory(cb.build());
          Twitter twitter = tf.getInstance();
              try {
                  Query query = new Query("Cocaine");
                  QueryResult result;
                  result = twitter.search(query);
                  List&lt;Status&gt; tweets = result.getTweets();
                  for (Status tweet : tweets) {
                      System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
                  }
  
                  System.exit(0);
              } catch (TwitterException te) {
                  te.printStackTrace();
                  System.out.println("Failed to search tweets: " + te.getMessage());
                  System.exit(-1);
              }
  </code></pre>
  
  <p>My index.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta http-equiv="Content-type" content="text/html; charset=utf-8"&gt;
      &lt;title&gt;Stock Analysis Using Hadoop Framework&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;form action ="TwitterCrawlServlet"&gt;
          &lt;input type="submit" value="send"/&gt;
      &lt;/form&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
    &lt;display-name&gt;FinalYearProject&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;servlet&gt;
      &lt;description&gt;&lt;/description&gt;
      &lt;display-name&gt;TwitterCrawlServlet&lt;/display-name&gt;
      &lt;servlet-name&gt;TwitterCrawlServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.fyp.pkg.TwitterCrawlServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;TwitterCrawlServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/TwitterCrawlServlet&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>I was able to run successfully for the TwitterCrawlServlet's code as a separate Java application. When I tried to run it on Tomcat. It shows <code>HTTP Status 500</code></p>
  
  <pre><code>Logs on my browser
  
  type Exception report
  
  message
  
  description The server encountered an internal error () that prevented it from fulfilling this request.
  
  exception
  
  javax.servlet.ServletException: Error instantiating servlet class com.fyp.pkg.TwitterCrawlServlet
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      java.lang.Thread.run(Thread.java:745)
  root cause
  
  java.lang.NoClassDefFoundError: twitter4j/TwitterException
      java.lang.Class.getDeclaredConstructors0(Native Method)
      java.lang.Class.privateGetDeclaredConstructors(Class.java:2595)
      java.lang.Class.getConstructor0(Class.java:2895)
      java.lang.Class.newInstance(Class.java:354)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      java.lang.Thread.run(Thread.java:745)
  root cause
  
  java.lang.ClassNotFoundException: twitter4j.TwitterException
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
      java.lang.Class.getDeclaredConstructors0(Native Method)
      java.lang.Class.privateGetDeclaredConstructors(Class.java:2595)
      java.lang.Class.getConstructor0(Class.java:2895)
      java.lang.Class.newInstance(Class.java:354)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/zUGco.jpg" rel="nofollow">My twitter4j classpath</a></p>