title: Java WebApp: ClassNotFoundException com.rabbitmq.client.ConnectionFactory
body: <p>I have the following maven dependency:</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;com.rabbitmq&lt;/groupId&gt;
          &lt;artifactId&gt;amqp-client&lt;/artifactId&gt;
          &lt;version&gt;3.5.6&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>And i have the following servlet:</p>
  
  <pre><code>package servlets;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.concurrent.TimeoutException;
  
  import javax.servlet.Servlet;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import com.rabbitmq.client.Channel;
  import com.rabbitmq.client.Connection;
  import com.rabbitmq.client.ConnectionFactory;
  
  import model.DVD;
  
  /**
   * Servlet implementation class LoginServlet
   */
  public class IndexServlet extends HttpServlet
  {
      private static final long serialVersionUID = 1L;
  
      /**
       * @see HttpServlet#HttpServlet()
       */
      public IndexServlet()
      {
          super();
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @see Servlet#init(ServletConfig)
       */
      public void init(ServletConfig config) throws ServletException
      {
          // TODO Auto-generated method stub
      }
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
       *      response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
      {
          // TODO Auto-generated method stub
          response.getWriter().append("Served at: ").append(request.getContextPath());
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
       *      response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
      {
          // TODO Auto-generated method stub
          String QUEUE_NAME = "hello";
  
          try
          {
  
              /// some code
  
              ConnectionFactory factory = new ConnectionFactory();
              factory.setHost("localhost");
              Connection connection = factory.newConnection();
              Channel channel = connection.createChannel();
  
              channel.queueDeclare(QUEUE_NAME, false, false, false, null);
              channel.basicPublish("", QUEUE_NAME, null, obj.getBytes());
              System.out.println(" [x] Sent '" + dvd.getName() + "'");
  
              channel.close();
              connection.close();
          } catch (IOException | TimeoutException | NumberFormatException exp)
          {
              exp.printStackTrace();
          }
  
          response.sendRedirect("/A3_Producer/");
      }
  
  }
  </code></pre>
  
  <p>I run Maven build with clean install and after that I start the web application in a tomcat server. The welcome page loads, but when I hit the Submit button and enter in this servlet, I get an <code>ClassNotFoundException</code> when trying to make a <code>ConnectionFactory</code> object.</p>
  
  <p>I added the jar too to build path but it didn't fix the problem.</p>
  
  <p>What can I do to fix it?</p>