问题
Got this error while trying opennlp chunking:
NoClassDefFoundError: opennlp/tools/chunker/ChunkerModel
Here is the basic code:
import java.io.*;
import opennlp.tools.chunker.*;
public class test{
public static void main(String[] args) throws IOException{
ChunkerModel model = null;
InputStream modelIn = new FileInputStream("en-parser-chunking.bin");
model = new ChunkerModel(modelIn);
}
}
回答1:
I don't see any NLP-specific reasons here, so just check tutorials about NoClassDefFoundError, for example:
Verify that all required Java classes are included in the application’s classpath. The most common mistake is not to include all the necessary classes, before starting to execute a Java application that has dependencies on some external libraries.
The classpath of the application is correct, but the Classpath environment variable is overridden before the application’s execution."
or related question.
In particular, check that you have appropriate (and only one) version of opennlp jar in your classpath.
*it is not a good style to import all content of the package (by using wildcard) - instead, use IDE's support: e.g. ctrl+shift+o in Eclipse (ctrl+alt+o in IDEA) automatically resolves all needed imports.
来源:https://stackoverflow.com/questions/29311650/noclassdeffounderror-opennlp-tools-chunker-chunkermodel