0

I'm getting an error while running my java web application. I have one servlet class and one class for Apache openNLP text analyzing. When I run my code (submit my form data to servlet) I get below error code in my browser

Error in my Browser

Also it shows below exception details in eclipse console.

enter image description here

Below is my project structure and I have placed the "en-parser-chunking.bin" file in highlighted area.

Project structure

Is there any better way to place my "en-parser-chunking.bin" file?

Cœur
  • 32,421
  • 21
  • 173
  • 232
user8048032
  • 135
  • 1
  • 1
  • 7

1 Answers1

2

First part of the answer:

1) Place the en-parser-chunking.bin into the WebContent/WEB-INF/classes or WebContent/WEB-INF/resources folder of your Eclipse project. These are directories in which the instance of WebappClassLoaderBase is allowed to load resources from at runtime of a web application.

2) With this code snippet (which is shortened for brevity):

String parserModelPath = "/WEB-INF/resources/en-parser-chunker.bin";
ParserModel model = new ParserModel(servletContext.getResourceAsStream(parserModelPath));

if(model!=null) {
    // From here, <model> is initialized and you can start playing with it...
    // Creating a parser
    Parser parser = ParserFactory.create(model);
    // Parse some things here 
    // ...
}

you should get a working Parser at runtime. For reference, see JavaDoc for ServletContext#getResourceAsStream and this StackOverflow post.

Second part of the answer:

1) Place the opennlp-tools-<opennlp-version>.jar file into WebContent/WEB-INF/lib or reference it in the Web-App's class path of your project setup. Thus, the library and its classes, such as opennlp.tools.parser.ParserModel, can be loaded and used at runtime of your project.

2) Re-bundle your war archive and redeploy it to your Tomcat's webapps directory.

Hope it helps, see also my similar answer.

MWiesner
  • 7,913
  • 11
  • 31
  • 66