stanfordnlp/CoreNLP · critical · javax.servlet.ServletException

Classifier class not found problem.

Error message

Classifier class not found problem.

What it means

CRFClassifier.getClassifier(is) resolves classes while deserializing the model; if a class referenced by the serialized stream cannot be found on the servlet's classpath, a ClassNotFoundException is caught and rethrown as this ServletException. It means the classifier file references classes (CoreNLP classes or custom feature classes) missing from the deployed WAR.

Solutions

  1. Add the matching Stanford CoreNLP models jar (same version as the CoreNLP jar) to WEB-INF/lib or the servlet container's shared classpath.
  2. Align CoreNLP and models jar versions exactly (e.g. corenlp 4.5.x jar + 4.5.x models).
  3. If the model was trained with custom classes, package those classes in the WAR.
  4. Inspect the ClassNotFoundException's class name in the cause chain to identify the missing jar.

Example fix

// before: only corenlp jar deployed
cp stanford-corenlp-4.5.4.jar WEB-INF/lib/
// after: also deploy matching models jar
cp stanford-corenlp-4.5.4.jar stanford-corenlp-4.5.4-models.jar WEB-INF/lib/
Defensive patterns

Strategy: validation

Validate before calling

// Check required jars are present before init
try {
  Class.forName("edu.stanford.nlp.ie.crf.CRFClassifier");
} catch (ClassNotFoundException e) {
  throw new IllegalStateException("CoreNLP jar missing from classpath");
}

Try / catch

try {
  model = CRFClassifier.getClassifier(is);
} catch (ClassNotFoundException e) {
  log.severe("Model references missing class: " + e.getMessage());
  throw new UnavailableException("Missing CoreNLP models jar");
}

Prevention

When it happens

Trigger: Servlet init with a serialized classifier whose classes are absent — e.g. models jar not on classpath, a model serialized with custom feature factories not shipped in the WAR, or a model from a newer CoreNLP referencing classes the old jar lacks.

Common situations: Deploying the WAR without the stanford-corenlp-x.y.z-models jar, upgrading CoreNLP jars but keeping old models (or vice versa), or shipping a classifier trained with custom code excluded from the build.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/3e9c2d5d0734a52e. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/ner/webapp/NERServlet.java:88

      String filename = "/WEB-INF/data/models/" + classifier;
      InputStream is = getServletConfig().getServletContext().getResourceAsStream(filename);

      if (is == null) {
        throw new ServletException("File not found. Filename = " + filename);
      }
      try {
        if (filename.endsWith(".gz")) {
          is = new BufferedInputStream(new GZIPInputStream(is));
        } else {
          is = new BufferedInputStream(is);
        }
        model = CRFClassifier.getClassifier(is);
      } catch (IOException e) {
        throw new ServletException("IO problem reading classifier.");
      } catch (ClassCastException e) {
        throw new ServletException("Classifier class casting problem.");
      } catch (ClassNotFoundException e) {
        throw new ServletException("Classifier class not found problem.");
      } finally {
        IOUtils.closeIgnoringExceptions(is);
      }
      ners.put(classifier, model);
    }
  }

  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
  {
    if (request.getCharacterEncoding() == null) {
      request.setCharacterEncoding("utf-8");
    }
    response.setContentType("text/html; charset=UTF-8");

    this.getServletContext().getRequestDispatcher("/header.jsp").
      include(request, response);

View on GitHub (pinned to 1b7edd19c4)