簡體   English   中英

Eclipse 無法從 Jar 加載 class

[英]Eclipse failed to load class from Jar

Eclipse JRE 4.15.0

I added stanford-corenlp-4.0.0.jar (loaded from https://stanfordnlp.github.io/CoreNLP/api.html ) to the Project/Build Path/Libraries/Classpath. 創建CoreDocument實例時

CoreDocument document = new CoreDocument("str");

Eclipse 自動建議

import edu.stanford.nlp.pipeline.StanfordCoreNLP;

然而在執行期間導入不起作用:

Exception in thread "main" java.lang.NoClassDefFoundError: edu/stanford/nlp/pipeline/CoreDocument
    at main.CoreNLP.main(CoreNLP.java:35)
Caused by: java.lang.ClassNotFoundException: edu.stanford.nlp.pipeline.CoreDocument

如何解決自動建議和運行時導入之間的這種不一致?

看起來這個庫不是獨立的。 即它取決於其他一些庫。 因此,您不能只將單個 JAR 添加到您的項目並運行為,因為您還需要添加該 JAR 的依賴項及其依賴項等。 這些依賴稱為傳遞依賴。

我怎么知道? 這是他們的下載頁面的內容:

斯坦福 CoreNLP 可以通過下面的鏈接下載。 This will download a large (536 MB) zip file containing (1) the CoreNLP code jar, (2) the CoreNLP models jar (required in your classpath for most tasks) (3) the libraries required to run CoreNLP , and (4)項目的文檔/源代碼。 這就是開始英語的一切,解壓縮這個文件。 打開生成的文件夾,您就可以使用它了。

看到第 3 項了嗎?

再引用一句:

Maven:您可以在 Maven Central 上找到 Stanford CoreNLP。 The crucial thing to know is that CoreNLP needs its models to run (most parts beyond the tokenizer and sentence splitter) and so you need to specify both the code jar and the models jar in your pom.xml, as follows: (Note: Maven發布通常在網站發布幾天后發布。)

因此,使用它的最佳方法是讓 Gradle 或 Maven 之類的構建工具下載所有依賴項並構建您的構建類路徑。 他們在該下載頁面上有 Maven 的示例:

<dependencies>
    <dependency>
        <groupId>edu.stanford.nlp</groupId>
        <artifactId>stanford-corenlp</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>edu.stanford.nlp</groupId>
        <artifactId>stanford-corenlp</artifactId>
        <version>4.0.0</version>
        <classifier>models</classifier>
    </dependency>
</dependencies>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM