HTTP状态500 - javax.servlet.ServletException:java.lang.NoClassDefFoundError:edu / stanford / nlp / tagger / maxent / MaxentTagger

时间:2016-03-23 12:28:42

标签: stanford-nlp pos-tagger

我正在尝试在jsp中对我的查询进行POS标记。当我作为一个Java应用程序运行它,它工作正常,但当我以jsp运行它时,我得到以下异常。

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: edu/stanford/nlp/tagger/maxent/MaxentTagger
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:548)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:454)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52

我的jsp代码如下。

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>welcome</h1>
<%@ page import="Search.SearchMain" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<% 
    List<String> res =new ArrayList<String>();
    String q = request.getParameter("sqry");
    res = SearchMain.search(q,1);
    for(String r : res){%>
        <%=r%>
    <%}
%>
</body>
</html>

我的java代码如下所示

package taggerPOS;

import java.util.ArrayList;
import java.util.List;

import edu.stanford.nlp.ling.HasWord;
import edu.stanford.nlp.ling.Sentence;
import edu.stanford.nlp.ling.TaggedWord;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;

public class Tagger {
    public static List<String> getTag(String query){
        List<String> nouns = new ArrayList<String>();
        MaxentTagger tagger = new MaxentTagger("tagger/english-left3words-distsim.tagger");
        String[] tokens = query.split("\\s+");
        List<HasWord> sent = Sentence.toWordList(tokens);
        List<TaggedWord> taggedSent = tagger.tagSentence(sent);
        //System.out.println(taggedSent);
        for (TaggedWord tw : taggedSent) {
              if (tw.tag().startsWith("NN")) {
                //System.out.println(tw.word());
                nouns.add(tw.word());
              }
            } 
        return nouns;
    }
    public static void main(String args[]){
        List<String> n = getTag("This sentence contains two noun phrases");
        for(String a:n){
            System.out.println(a);
        }
    }
}

我已将Stanford-POStagger.jar添加到类路径中,并且还添加了tagger模型。 This is my project structure

1 个答案:

答案 0 :(得分:0)

尝试将您的jar添加到/ WEB-INF / lib文件夹,以便tomcat可以找到它们

(如此处所述:java.lang.NoClassDefFoundError: org/apache/commons/discovery/tools/DiscoverSingleton