Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in Stanford CoreNLP: java.lang.NoClassDefFoundError

I downloaded the Stanford CoreNLP and when I run the code which is given in their website. I get an error in this line

StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

The error is as follows

Exception in thread "main" java.lang.NoClassDefFoundError: nu/xom/Node at sample1.main(sample1.java:35)
Caused by: java.lang.ClassNotFoundException: nu.xom.Node
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
... 1 more

I use Eclipse IDE, should I do some configuration? Please help me out with it!

like image 949
CTsiddharth Avatar asked Mar 02 '12 04:03

CTsiddharth


2 Answers

I have downloaded the stanford-corenlp-2012-01-08.tgz from the link you provided. Using 7-zip I have uncompressed it and found another compressed file with name stanford-corenlp-2012-01-08 and again uncompressed it using 7-zip. The content is shown below: enter image description here

Then I created a new Java Project in eclipse and created a new folder lib inside that project and put

  • joda-time.jar
  • stanford-corenlp-2011-12-27-models.jar
  • stanford-corenlp-2012-01-08.jar
  • xom.jar

jars to the lib. Then set the project Java Build Path to these jars.

enter image description here

Next I created a test class with main method.

import java.util.Properties;

import edu.stanford.nlp.pipeline.StanfordCoreNLP;


public class NLP {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Properties props = new Properties();
        props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
        StanfordCoreNLP coreNLP = new StanfordCoreNLP(props);
    }

}

And lastly run the application. The output is depicted below:

enter image description here

It runs successfully.

Hope this will help you.

like image 198
Tapas Bose Avatar answered Nov 15 '22 05:11

Tapas Bose


I had the same problem using stanford-corenlp-full-2014-10-31.

Tapas Bose's answer is very good, but for this current version (and maybe other earlier ones), you also need to include another two .jar files to get rid of the error:

  • ejml-0.23.jar
  • jollyday.jar

The developers updated this information on the website, too:

To process one file using Stanford CoreNLP, use the following sort of command line (adjust the JAR file date extensions to your downloaded release):

java -cp stanford-corenlp-VV.jar:stanford-corenlp-VV-models.jar:xom.jar:joda-time.jar:jollyday.jar:ejml-VV.jar -Xmx2g edu.stanford.nlp.pipeline.StanfordCoreNLP [ -props <YOUR CONFIGURATION FILE> ] -file <YOUR INPUT FILE>
like image 30
Berilac Avatar answered Nov 15 '22 04:11

Berilac