Search code examples
javaintellij-ideastanford-nlp

java.lang.NoClassDefFoundError: edu/stanford/nlp/parser/lexparser/LexicalizedParser


I am working with Stanford Parser API. My system specifications are listed below:

OS: Win8

IDE: .IntelliJIdea14

JDK: 1.8

Stanford-Parser 3.5.2 Version

I have imported stanford-parser.jar and ejml-0.23.jar in module dependencies (ClassPath). There are some parser models that are saved in a jar file named stanford-parser-3.5.2-models.

The Stanford support team says:

"In recent distributions, the models are included in a jar file inside the parser distribution. For example, in the 2012-11-12 distribution, the models are included in stanford-parser-2.0.4-models.jar The easiest way to access these models is to include this file in your classpath. The parser will then be able to read the models from that jar file. "

But I can't import stanford-parser-3.5.2-models.jar file. So I extracted it, save the model in an appropriate address in D Drive and finally changed the following code:

String parserModel = "edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz";

LexicalizedParser lp = LexicalizedParser.loadModel(parserModel);

To

String parserModel = "D:\\ MasterofScience\\Tools\\Stanford Dependenct Tree\\models" +
    "\\lexparser\\englishPCFG.ser.gz";

 LexicalizedParser lp = LexicalizedParser.loadModel(parserModel);

But I give these exception errors:

Exception in thread "main" java.lang.NoClassDefFoundError: edu/stanford/nlp/parser/lexparser/LexicalizedParser
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:119)
Caused by: java.lang.ClassNotFoundException: edu.stanford.nlp.parser.lexparser.LexicalizedParser
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more

Even I Don’t change the code, I receive the same exception! What should I do?


Solution

  • You're missing the parser jar (stanford-parser.jar) in your classpath. Really, you can add both the parser jar and the model jar to your classpath, and then the program should work.