stanfordnlp/CoreNLP · critical · javax.servlet.ServletException
File not found. Filename = " + filename
Error message
File not found. Filename = " + filename
What it means
During init(), NERServlet loads each configured classifier model via ServletContext.getResourceAsStream. If the stream is null — the resource '/WEB-INF/data/models/<classifier>' does not exist in the webapp — it throws ServletException naming the missing filename.
Solutions
- Copy the required classifier model files into src/main/webapp/WEB-INF/data/models/ and rebuild the WAR
- Match the classifier init-param names exactly to the filenames present in WEB-INF/data/models
- Check the build (Maven/Gradle) isn't filtering/excluding model resources from the WAR
- Verify inside the deployed webapp container (not just the source tree) that the resource resolves
Example fix
<!-- before --> <init-param><param-name>classifiers</param-name><param-value>english.all.3class.distsim.crf.ser.gz</param-value></init-param> <!-- after: also ensure the file exists --> # cp english.all.3class.distsim.crf.ser.gz webapp/WEB-INF/data/models/ <init-param><param-name>classifiers</param-name><param-value>english.all.3class.distsim.crf.ser.gz</param-value></init-param>
Defensive patterns
Strategy: try-catch
Validate before calling
for (String c : classifierNames) {
if (getServletContext().getResourceAsStream("/WEB-INF/data/models/" + c) == null)
throw new IllegalStateException("Model missing from WAR: " + c);
} Try / catch
try { servlet.init(cfg); } catch (ServletException e) { if (e.getMessage().startsWith("File not found")) redeployWithModels(); } Prevention
- Bundle model files inside WEB-INF/data/models in the build
- Verify WAR contents (jar tf app.war | grep models) before deploy
- Keep init-param filenames in sync with packaged resources
When it happens
Trigger: init-param listing classifier model files that were never placed under the webapp's WEB-INF/data/models directory; misspelled model filenames; WAR packaging that excludes .ser/.gz model files.
Common situations: Building the WAR without the large model files (excluded by build config or .gitignore); renaming models on disk but not in the classifier init-param; deploying a slimmed distribution.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Couldn't load classifier from
- Invalid outputFormat setting.
- Invalid preserveSpacing setting.
- IO problem reading classifier.
- Could not find inside
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/abc204fb1dde97d4.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/ner/webapp/NERServlet.java:74
String path = getServletContext().getRealPath("/WEB-INF/data/models");
for (String classifier : new File(path).list()) {
classifiers.add(classifier);
}
// TODO: get this from somewhere more interesting?
defaultClassifier = classifiers.get(0);
for (String classifier : classifiers) {
log(classifier);
}
ners = new HashMap<>();
for (String classifier : classifiers) {
CRFClassifier<CoreMap> model = null;
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);View on GitHub (pinned to 1b7edd19c4)