[Solved]: java.lang.NoClassDefFoundError in Standford Core NLP

Problem Statement: java.lang.NoClassDefFoundError in Standford Core NLP

If you are getting Class not found error something like this:

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

or

java.lang.NoClassDefFoundError: edu/stanford/nlp/pipeline/StanfordCoreNLP


Answer:

Two Reason can be for this:

  1. You don’t have jar which contains called class or
  2. Your jar is corrupted.

1. You don’t have jar

Add these maven dependencies to get all jar related to standford NLP.

 <properties>    <stanford.corenlp.version>3.9.1</stanford.corenlp.version>  </properties>  <dependencies>             <dependency>            <groupId>edu.stanford.nlp</groupId>           <artifactId>stanford-corenlp</artifactId>           <version>${stanford.corenlp.version}</version>       </dependency>        <dependency>            <groupId>edu.stanford.nlp</groupId>           <artifactId>stanford-corenlp</artifactId>           <version>${stanford.corenlp.version}</version>           <classifier>models</classifier>         </dependency>  </dependencies>

2. Your jar is corrupted

Simply goto .m2 folder and remove all jars of Standford NLP. Again download jar from central repo.