I am trying to build a customized StanfordNer model, training data and properties file are ready.
But when I am trying to run the following code :
java -cp "stanford-ner.jar:lib/*" -mx4g edu.stanford.nlp.ie.crf.CRFClassifier -prop download.txt
This error is popping out :
Error: Could not find or load main class
edu.stanford.nlp.ie.crf.CRFClassifier
Steps followed:
Downloaded and extracted stanford-ner-2018-10-16.zip file.
Java 8 installed and $JAVA_HOME has been set.
The properties file (download.txt) has been placed in the folder where stanford-ner-2018-10-16.zip is extracted.
If you are seeing errors like that it means your CLASSPATH is not properly configured.
You need to run that command in the same folder as the NER download or it won't find the needed jars. That command should be run in whatever directory has stanford-ner.jar and lib in it. Alternatively you can just set the CLASSPATH environment variable and remove the -cp option from the command.
More info on Java CLASSPATH here: https://docs.oracle.com/javase/tutorial/essential/environment/paths.html
Related
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.
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).
Have you downloaded the various jar files into your root directory? That sounds like an organizational nightmare.
If not, though, that explains why java -cp "*" does not work. You need to figure out what subdirectory has your CoreNLP distribution and make that the directory in your classpath:
java -cp "c:\Users\john\nlp\codebase\CoreNLP\lib\*" ... for example, if you're me
If you need multiple directories on a Windows machine, the correct separator is ;
I have developed an application which results serial ports in combobox, but when I am running .jar file of my application using command terminal using command:
Java -jar Serial_Send.jar //where Serial_Send is name of my jar file
It is resulting into an error Cannot find javax.comm.properties.
But javax.comm.properties file is present in java_home/jre/lib directory.
What else I have to do in order to resolve this.
Try the following command:
java -jar -Djava.class.path=java_home/jre/lib Serial_Send.jar
This will put the lib directory in class path of program explicitly.
I'm getting the following error when I try to run the 'jar' command in the command line on windows :
'jar' is not recognized as an internal or external command
The general solution seems to be that I need to add the jdk bin folder to the PATH in environment variables. I have already done this, I added the following to the path variable :
...; C:\Program Files\Java\jdk1.8.0_40\bin\;
Though I'm not sure if having the jdk reside in 'program files' instead of 'program files x86' affects this. I'm on 64 bit windows with 64 bit java.
Thanks
The path should only contain directories where the OS will look for executables. Strip the trailing "\jar.exe" to set your path as:
(old path variables here);C:\Program Files (x86)\Java\jdk1.7\bin
Thanks To : #stevevls
Try using this command:
java -version
If it doesn't work that means you failed to properly add path to jdk.
If it does work, try using:
java -jar
The jar command in command line is used in order to create a JAR file. For example:
jar cf jar-file input-file(s)
See more at: Oracle docs
If you want to run the existed JAR file you should use the java -jar command mentioned by #Aleksandr.
But in your case it looks like you don't have an access to the added directory in your path with JKD binaries so at the beginning try to execute mentioned java --version to check whether you have java in you classpath at all.
Please remember that on Windows you have to restart the console when you change the windows default path. You do not see the changes on the current console.
The x64 version of Java is installed on Program Files. The x86 version is installed on Program Files x86 by default.
Five steps to solve this problem:
check whether in your bin folder jar.exe is availbale or not
check for your environmental setting
download jar file from here http://originaldll.com/file/jar.exe/29248.html and keep in bin folder
now check for jar it will 100% work
keep any jar in your desktop and go to desktop path on cmd prompt and run the command jar xf filename.jar
Now see if it is working
I have the classic :
java.lang.NoClassDefFoundError: org/python/util/jython
Even if the jar jython.jar exist in the environment variable PATH for my user and system wide path.
How can I quickly test that I am not crazy and it is indeed in the path?
Java doesn't use the PATH variable.
To specify the classpath when running a java application use the -cp parameter for the java command.
Inside your batch file (the .cmd file) find the java command and add the needed jar file:
java -cp somefile.jar;\path\to\jython.jar someclass.MainMethod
Please don't use the deprecated CLASSPATH any more.
For more details, please see the Java documentation:
http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html#tooloption
use the following command
set classpath="path to your jar/jython.jar";
I'm trying to run Java program using cmd.
When I compile that file using
javac helloworld.java
It works perfectly but when I try to run that file using
java helloworld
I get an error:
couldn't find or load main class.
even though my I put my javac path in class path in system variables and javac working correctly.
After searching on how I can fix it I found that I can use
java -cp . helloworld
because it let you to find .class file.
and it works but I know that I can run java program without this -cp so what this for and how I can run my program without it?
-cp specifies the Java classpath for the JRE you are attempting to start. Look for an environment variable CLASSPATH and add '.'.
-cp is used to set the classpath for the jar file, this flag is same as importing a jar file to eclipse and then use it.
If you want to run without this flag, use should set the classpath first beforing running.
export CLASSPATH=path/to/your/jarfile.jar
If you already have some classpath set
export CLASSPATH=$CLASSPATH:path/to/your/jarfile.jar
If you want to include current directory
export CLASSPATH=$CLASSPATH:path/to/your/jarfile.jar:.
As other have mentioned, you can set the CLASSPATH. However, a much better approach is to bundle the .class files in a JAR ans user java -jar nameofthejar.jar.