在我下面的 servlet 类中,我在 tomcat 服务器中部署时收到一些 NoClassDefFoundError: antlr/RecognitionException 和 NoClassDefFoundError: antlr/TokenStreamException。带有*的星号线是导致它的原因。当我评论这些行时,它很容易部署。我在 Eclipse 的构建路径中包含了必要的 .jar 文件。
基本上在下面的 Servlet 我想从 web 调用我的 java 程序。当我从控制台使用我的 Java 代码时,它不会出现任何错误并且运行良好。对于我的大多数外部包含的 jar 文件,catalina.out 都在为 NoClassDefFound 哭泣。我是否遗漏了某些东西或对于 Servlet,我必须在某处指定有关外部 jar 类的信息?
提前致谢..
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);
}
}