title: Exception using selenium on server side
body: <p>I have a web application which asks user to input a URL. I then, using <a href="https://code.google.com/p/selenium/" rel="nofollow">Selenium 2.35.0</a>, grabbing the source code from the URL.</p>
  
  <p>I have created a <code>dynamic web project</code> with everything setup properly (all selenium jars included), but my application is throwing exception </p>
  
  <pre><code>Oct 18, 2013 2:49:48 PM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet [DiffReportServlet] in context with path          [/PBSkyScraper] threw exception [Servlet execution threw an exception] with root cause
  java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
  at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
  at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
  at com.PB.automation.servlets.DiffReportServlet.doGet(DiffReportServlet.java:38)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  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:222)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
  at java.lang.Thread.run(Thread.java:680)
  </code></pre>
  
  <p>This is what the workflow is : </p>
  
  <p>The user enters the URL and submits. A servlet is called which actually does the job of grabbing the source code. I am unable to understand the reason because the same works if i try it running as a java application and not on server.</p>
  
  <p>Here is the code</p>
  
  <pre><code> /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
      String webDir = request.getServletContext().getRealPath("/WebContent");
      String url = request.getParameter("url");
      ApplicationUtils.getHTMLSourceFromURL(url, "originalSource.html");
  
  }
  
  public static void getHTMLSourceFromURL(String url, String originalFile) {
  
      WebDriver driver = new FirefoxDriver();
      driver.get(url);
  
      try {
          Thread.sleep(5000);
  
          List&lt;String&gt; pageSource = new ArrayList&lt;String&gt;(Arrays.asList(driver.getPageSource().split("\n")));
  
          writeTextToFile(pageSource, originalFile);
  
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
  
      System.out.println("quitting webdriver");
      driver.quit();
  }
  </code></pre>
  
  <p>Can somebody explain the cause and provide some solution to this? I am using Tomcat as the server.</p>