1

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 * 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.

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?

Thanks in advance..

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<String> list = new ArrayList<String>();
    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);
}
}
Andremoniy
  • 34,031
  • 20
  • 135
  • 241
Parth
  • 51
  • 1
  • 5

1 Answers1

1

You need to put the ANTLR v2 Library in the lib folder of Tomcat (see comment). Java searches for libraries in specific directories. The libraries you want to use have to be in one of these directories to be found by Java/Tomcat.

If you want Eclipse to deploy dependencies automatically maybe this will help:

Eclipse Web Project Dependencies

Community
  • 1
  • 1
th3falc0n
  • 1,389
  • 1
  • 12
  • 33
  • Yes, Thanks. created "lib" directory in WEB-INF and copied all .jar files in there and solved the error. Thanks. – Parth Feb 08 '13 at 09:31