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.