Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.8k views
in Technique[技术] by (71.8m points)

Could not find or load main class -- Stanford CoreNLP -- Java

I'm new to java (I have Java 8) and trying to run a CoreNLP pipeline in CMD:

C:>java -Xmx5g edu.stanford.nlp.pipeline.StanfordCoreNLP -file dr19ald.txt

and keep getting:

Error: Could not find or load main class edu.stanford.nlp.pipeline.StanfordCoreNLP

I've looked through similar posts and it seems to be a classpath problem so I tried the following to no avail:

C:>java -cp "C:/stanford-corenlp-4.2.0-models-spanish.jar" edu.stanford.nlp.pipeline.StanfordCoreNLP -file dr19ald.txt

Have I added the classpath incorrectly or is there another problem I'm missing?

UPDATE: I've now tried:

C:>java -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLP -file dr19ald.txt

and

C:>java -cp "C:/*" edu.stanford.nlp.pipeline.StanfordCoreNLP -file dr19ald.txt

with the same error message.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The reference for the command line indicates that you should include more than just one jar in the classpath. They use all distributed jars (*).

Depending on your Java's version (8 or higher) you should also specify a modules directive.

edit

I further investigated the situation and it is rather messy. The distribution includes some third party libraries as well as their source code in JAR format. Other libraries are not included at all, though they are referenced in the pom.xml (and downloaded if you have the tools).

A key problem is that the JAXB Apis/Impl are not part of the Java 11 package anymore and that the code is undergoing some mutations on its way to Jakarta EE. The Java 8 still includes a JAXB implementation, though the distribution includes newer standalone files. The code has a dependency on the class com.sun.istack.FinalArrayList which is not included in the distribution but in the older com.sun.xml.bind:jaxb-core that is referenced in the POM.

Solution

You need to download the utility JAR istack-commons-runtime-3.0.7.jar (try https://mvnrepository.com/artifact/com.sun.istack/istack-commons-runtime). I placed it in a subdirectory "m2" and referenced it in the script as REPO.

I wrote a little Windows cmd script to start the processing.

REM  run the Stanford CoreNLP on an input file 
@echo off 
SET JARS=stanford-corenlp-4.2.0.jar;stanford-corenlp-4.2.0-models.jar
SET JARS=%JARS;jollyday.jar;xom.jar;joda-time.jar;ejml-core-0.39.jar
SET JARS=%JARS%;ejml-ddense-0.39.jar;ejml-simple-0.39.jar;slf4j-api.jar
SET JARS=%JARS%;slf4j-simple.jar;protobuf.jar;javax.activation-api-1.2.0.jar
SET JARS=%JARS%;jaxb-api-2.4.0-b180830.0359.jar;jaxb-impl-2.4.0-b180830.0438.jar

SET REPO=m2
SET JARS=%JARS%;%REPO%istack-commons-runtime-3.0.7.jar

@echo on
java -Xmx3g -cp %JARS% edu.stanford.nlp.pipeline.StanfordCoreNLP -file %1

I placed this script into the directory where I extracted the distribution ZIP.

Now I can open a Windows Command Prompt, navigate to the distribution directory and start my script, passing the input file as parameter (the %1 in the script).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...