title: How to Resolve ClassNotFoundException with BSON in Tomcat?
body: <p>I'm writing a Tomcat 8 application that works fine unless I attempt to instantiate any MongoDB class in my servlet's POST handler.</p>
  
  <p>According to the <a href="https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#reference-compatibility-language-java" rel="nofollow noreferrer">Java driver documentation</a>, Mongo 3.0.x is compatible with Java 7. As the <a href="http://mongodb.github.io/mongo-java-driver/3.2/driver/getting-started/installation-guide/" rel="nofollow noreferrer">Installation Guide</a> describes, the normal driver with bson and mongodb-driver-core as dependencies is recommended. So I included mongodb-driver in my pom.xml and downloaded and included the dependencies as external JARs (all version 3.0.4), but received the exception and stack trace when running the servlet. I then attempted the Uber jar (mongo-java-driver), but that made no impact. Just to be able to instantiate a Document, I included just the BSON as an external JAR and then in my pom.xml, still no change.</p>
  
  <p>I've also tried cleaning the Eclipse/Maven project and different versions of the dependencies.</p>
  
  <p>MongoDB version: 3.2.11
  <br/>Java compiler version: 1.7
  <br/>Driver version: 3.0.4
  <br/>Tomcat version: 8</p>
  
  <p>Stack trace:</p>
  
  <pre><code>25-Dec-2016 14:17:41.196 SEVERE [http-nio-5000-exec-15] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [Login] in context with path [/genebase] threw exception [Servlet execution threw an exception] with root cause
  java.lang.ClassNotFoundException: org.bson.Document
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1295)
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1147)
  at seismic.servlet.Login.post(Login.java:17)
  ...
  </code></pre>
  
  <p>The servlet:</p>
  
  <pre><code>import org.bson.Document;
  
  import java.net.UnknownHostException;
  
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  @SuppressWarnings("serial")
  public abstract class Servlet extends HttpServlet {
  
      public void doPost(HttpServletRequest req, HttpServletResponse res) {
          try {
              new Document();
          } catch (UnknownHostException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>What could be causing this exception?</p>