Stanford-NLP: Could not find main class error

早过忘川 提交于 2019-12-11 11:37:11

问题


This question seems to have been answered a few times (What does "Could not find or load main class" mean? and https://stackoverflow.com/a/16208709/2771315) but for some reason none of the shared methods are working.

What I've done so far.

1) Navigated to the directory containing the CoreNLP source files in terminal: ~/Downloads/CoreNLP-master/src

2) Selected one of the packages as a test case e.g. executed the command java -cp "*" -mx5g edu.stanford.nlp.sentiment.SentimentPipeline -file foo.txt (as per the docs, http://nlp.stanford.edu/sentiment/code.html)

I've tried variations of the above by altering the classpath -cp condition and setting it using set CLASSPATH = $CLASSPATH=~/Downloads/CoreNLP-master/src but can't seem to get a result. Does anyone know what I'm doing wrong? If I were to hazard a guess, I think that there is something wrong with the classpath but I'm not sure what.


回答1:


The classpath should point to the classes, not the source files. If you're using the GitHub version of the code, you can set the classpath to be:

-cp ~/Downloads/CoreNLP-master/classes:/path/to/corenlp/models.jar

You can find the most recent version of the CoreNLP models at: http://nlp.stanford.edu/software/stanford-corenlp-models-current.jar (warning: >200MB file)

If you have one of the corenlp releases, you should set your classpath to:

-cp /path/to/corenlp.jar:/path/to/corenlp/models.jar

For example:

export CLASSPATH=stanford-corenlp-3.9.1.jar:stanford-corenlp-3.9.1-models.jar

Both the corenlp jar and the models jar should show up in the zipped release of the code (e.g., from http://nlp.stanford.edu/software/corenlp.shtml)




回答2:


This worked perfectly fine for me.

java -cp "../*" -mx1g edu.stanford.nlp.sentiment.SentimentPipeline -file test.txt 

Run this command while you are in the classes directory.




回答3:


You are trying to run the program, instead of compiling it.



来源:https://stackoverflow.com/questions/27955569/stanford-nlp-could-not-find-main-class-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!