【问题标题】:Stanford-NLP: Could not find main class errorStanford-NLP:找不到主类错误
【发布时间】:2015-01-15 01:43:51
【问题描述】:

这个问题似乎已经回答了几次(What does "Could not find or load main class" mean?https://stackoverflow.com/a/16208709/2771315),但由于某种原因,没有一个共享方法有效。

到目前为止我做了什么。

1) 在终端导航到包含 CoreNLP 源文件的目录:~/Downloads/CoreNLP-master/src

2) 选择其中一个包作为测试用例,例如执行命令java -cp "*" -mx5g edu.stanford.nlp.sentiment.SentimentPipeline -file foo.txt(根据文档,http://nlp.stanford.edu/sentiment/code.html

我通过更改类路径-cp 条件并使用set CLASSPATH = $CLASSPATH=~/Downloads/CoreNLP-master/src 设置它尝试了上述变体,但似乎无法获得结果。有谁知道我做错了什么?如果我冒险猜测,我认为类路径有问题,但我不确定是什么。

【问题讨论】:

标签: java terminal stanford-nlp


【解决方案1】:

类路径应该指向类,而不是源文件。如果您使用的是 GitHub 版本的代码,您可以将类路径设置为:

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

您可以在以下位置找到最新版本的 CoreNLP 模型:http://nlp.stanford.edu/software/stanford-corenlp-models-current.jar(警告:>200MB 文件)

如果你有 corenlp 版本之一,你应该将你的类路径设置为:

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

例如:

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

corenlp jar 和模型 jar 都应显示在代码的压缩版本中(例如,来自 http://nlp.stanford.edu/software/corenlp.shtml

【讨论】:

  • 嗨,Gabor,感谢您的回复。当我使用 GitHub 版本的代码时,~/Downloads/CoreNLP-master/classes 似乎是空的。结果,我下载了 CoreNLP 3.5.0 版本。我尝试了以下java -cp ~/Downloads/stanford-corenlp-full-2014-10-31/stanford-corenlp-3.5.0.jar:~/Downloads/stanford-corenlp-full-2014-10-31/stanford-corenlp-3.5.0-models.jar edu.stanford.nlp.sentiment.Evaluate edu/stanford/nlp/models/sentiment/sentiment.ser.gz test.txt,这是nlp.stanford.edu/sentiment/code.html 上提供的另一个示例。我上面的命令正确吗?
  • 该命令看起来正确。对于 Github 版本的代码,您首先必须使用 ant(“$ ant”)编译项目。如果您获得了其他未找到的类,您可能需要包含该版本中包含的各种其他库(请参阅github.com/stanfordnlp/CoreNLP/tree/master/lib -- xom、jodatime 和 jollyday 是成本常见的)。
  • 使用非 Github 版本我在org/ejml/simple/SimpleBase 上得到一个NoClassDefFoundError 异常。查看org/ejml/simple/ 我可以看到SimpleBase 类存在。我已经从您建议的库存储库中替换了ejml-0.23.jar,但无济于事。你知道为什么会这样吗?
  • 您的类路径中是否包含 ejml-0.23.jar?
  • ejml-0.23.jar 在~/Downloads/stanford-corenlp-full-2014-10-31/ 中,所以可能不是。我试过java -cp ~/Downloads/stanford-corenlp-full-2014-10-31/stanford-corenlp-3.5.0.jar:~/Downlo‌​ads/stanford-corenlp-full-2014-10-31/* edu.stanford.nlp.sentiment.Evaluate edu/stanford/nlp/models/sentiment/sentiment.ser.gz test.txt 将所有.jar 文件包含在CoreNLP 中,但它似乎不起作用。你知道如何将它添加到类路径中吗?
【解决方案2】:

这对我来说非常好。

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

在类目录中运行此命令。

【讨论】:

    【解决方案3】:

    您正在尝试运行程序,而不是编译它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-18
      • 1970-01-01
      • 2012-08-12
      • 1970-01-01
      相关资源
      最近更新 更多