title: NoClassDefFoundError: antlr/RecognitionException in servlet but works in normal java program
body: <p>In my below servlet class I am getting some NoClassDefFoundError: antlr/RecognitionException and NoClassDefFoundError: antlr/TokenStreamException while deploying in the tomcat server. The starred lines with <strong>*</strong> are the ones which cause it. When I comment those lines, its easily deployed. I have included necessary .jar files in the build path of eclipse.</p>
  
  <p>Basically in below Servlet I want to call my java program from web. When I use my Java code from the console it does not give any error and runs quite well. For most of my externally included jar files, the catalina.out is crying for NoClassDefFound. Am I missing something or for Servlet, I have to specify somewhere about the external jar classes?</p>
  
  <p>Thanks in advance..</p>
  
  <pre><code>package i2r.hlt.iris;
  
  import i2r.hlt.iris.utils.JSenti;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Scanner;
  
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.antlr.v4.runtime.RecognitionException;
  
  import antlr.TokenStreamException;
  
  
  
  import es.upv.nlel.utils.FileIO;
  
  public class UserInputServlet extends HttpServlet {
  
  @Override
  public void init(ServletConfig config) throws ServletException {
      ServletContext context = config.getServletContext();
      homeJsp = context.getRequestDispatcher("/WEB-INF/jsp/iris.jsp");
  
      ....
  
      ret.setIndexPath(index_path);
  
      try {
          ret.loadUtts();
          ret.loadDlgs();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  }
  
  private RequestDispatcher homeJsp, userInput;
  private Retrieval ret;
  
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
          throws ServletException, IOException {
  
  
      String input = req.getParameter("user");
      req.setAttribute("message", input);
  
      homeJsp.forward(req, resp);
  }
  
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
          throws ServletException, IOException{
  
  
      String input = req.getParameter("user");
  
      List&lt;String&gt; list = new ArrayList&lt;String&gt;();
      list.add(input);
  
      Add add = new Add();
      String out = null;
  
  /*******            try {
  *****           out = "IRIS: " + FileIO.fileToString(new File(ret.uttMap.get(ret.selectBestUtt(list))));
  *****           } catch (antlr.RecognitionException e) {
  *****               throw new ServletException(e);
  *****           }catch (TokenStreamException e) {
  *****           throw new ServletException(e);
  *****           }*/
  
      req.setAttribute("message", out);
      homeJsp.forward(req, resp);
  }
  }
  </code></pre>