简体   繁体   English

Eclipse 无法从 Jar 加载 class

[英]Eclipse failed to load class from Jar

Eclipse JRE 4.15.0 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. I added stanford-corenlp-4.0.0.jar (loaded from https://stanfordnlp.github.io/CoreNLP/api.html ) to the Project/Build Path/Libraries/Classpath. When creating a CoreDocument instance创建CoreDocument实例时

CoreDocument document = new CoreDocument("str");

Eclipse autosuggests to Eclipse 自动建议

import edu.stanford.nlp.pipeline.StanfordCoreNLP;

Yet during execution the import does not work:然而在执行期间导入不起作用:

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

How can I fix this inconsistency between the autosuggestion and the runtime import?如何解决自动建议和运行时导入之间的这种不一致?

Looks like this library is not standalone.看起来这个库不是独立的。 Ie it depends on some other libraries.即它取决于其他一些库。 So you cannot just add a single JAR to your project and run as, as you need to also add that JAR's dependencies and their dependencies and so on.因此,您不能只将单个 JAR 添加到您的项目并运行为,因为您还需要添加该 JAR 的依赖项及其依赖项等。 Those dependencies are called transitive dependencies.这些依赖称为传递依赖。

How do I know that?我怎么知道? Here is what their download page says:这是他们的下载页面的内容:

Stanford CoreNLP can be downloaded via the link below.斯坦福 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) documentation / source code for the project. 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)项目的文档/源代码。 This is everything for getting going on English, Unzip this file.这就是开始英语的一切,解压缩这个文件。 open the folder that results and you're ready to use it.打开生成的文件夹,您就可以使用它了。

See that item #3?看到第 3 项了吗?

One more quote:再引用一句:

Maven: You can find Stanford CoreNLP on Maven Central. 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 releases are usually made several days after a release on the website.) 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发布通常在网站发布几天后发布。)

So, the best way to use it will be to let a build tool like Gradle or Maven download all the dependencies and construct your build classpath.因此,使用它的最佳方法是让 Gradle 或 Maven 之类的构建工具下载所有依赖项并构建您的构建类路径。 They have examples for Maven on that downloads page :他们在该下载页面上有 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.

相关问题 eclipse indigo的链接资源中的jar文件给出“无法从中加载Main-Class清单属性 <jar file path> ” - jar file in linked resources of eclipse indigo give “Failed to load Main-Class manifest attribute from <jar file path>” 无法从Windows上的jar加载Main-Class清单属性 - Failed to load Main-Class manifest attribute from a jar on windows 从jar加载一个类 - Load a class from a jar 在可能的恶意软件.jar文件中“无法从client.jar加载Main-Class清单属性”? - “Failed to load Main-Class manifest attribute from client.jar” in a possible malware .jar file? 如何从Jar中加载课程? - How to load class from Jar? “无法从”类路径上的jar加载Main-Class清单属性 - “Failed to load Main-Class manifest attribute from” a jar on the class path 从jar加载图像并在eclipse中加载图像 - Load image from jar and outside it in eclipse 如何从不受保护的上下文中加载由 jar2exe 加密或保护的 class 文件,例如 Eclipse Birt? - How to load a class file encrypted or protected by jar2exe from unprotected context, for example, Eclipse Birt? SLF4J:无法在 Eclipse 加载 class - SLF4J: Failed to load class at Eclipse 为什么它无法从JAR文件加载主类清单属性? - Why has it failed to load main-class manifest attribute from a JAR file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM