I am trying to run a java program in linux server which includes an imported jar.
While compiling it is not giving any issues , but when I try to run, it is giving an error "Error: Could not find or load main class ". If I remove the import and its references , my code is working fine without any load issues.
Any inputs please
javac -cp "/opt/CARKaim/sdk/pwdsdk.jar" SamplePwd.java //No issues
java -cp "/opt/CARKaim/sdk/pwdsdk.jar" SamplePwd //Error: Could not find or load main class
Assuming SamplePwd has an entry-point (e.g. main(String[] args)) make sure the current folder is also in your class-path, like
java -cp "/opt/CARKaim/sdk/pwdsdk.jar:." SamplePwd
Related
Using Java 8
I have set my PATH as 'C:\Program Files\Java\jdk1.8.0_144\bin'
I also tried to set my CLASSPATH as 'C:\Program Files\Java\jre1.8.0_144\lib\rt.jar', though I read it is not neccesary.
From Class01.java I have no problem creating Class01.class
javac Class01.java -> created Class01.class
Still, when I try to run program
java Class01
I got message
Error: Could not find or load main class Class01
If anyone know, how to fix this, I appreciate every hint.
Btw. My program does nothing but printing Hello world, if it has something to do with my problem.
You will need to tell Java about the classpath where it should find your file. I think you are missing the classpath parameter in your java command (see below). Here is a simple example how you could create a java file, compile and run it:
A. Create File:
public class X {
public static void main(String[] args) {
System.out.println("Blah!");
}
}
B. Compile:
"%JAVA_HOME%\bin\javac" X.java
C. Run it using the `-classpath` parameter:
"%JAVA_HOME%\bin\java" -classpath . X
This will print out:
Blah!
Note that JAVA_HOME is a System variable in Windows which needs to point to the location of your Java Runtime Environment.
I successfully compiled StanfordCoreNlpDemo by running:
javac -cp "*" StanfordCoreNlpDemo.java
and it compiled successfully. I then tried to run it with:
java -cp "*" StanfordCoreNlpDemo
I then received the following error:
Error: Could not find or load main class StanfordCoreNlpDemo
I realize this is a CLASSPATH issue so I tried to add the path to the folder:
/some/path/stanford-corenlp-full-2016-10-31/*
Nonetheless, I still get the same error. How do I run StanfordCoreNlpDemo.java?
This is not a problem of StanfordCoreNlpDemo program because I ran that code in Netbeans before. The problem seems associated with classpath issue.
Since the StanfordCoreNlpDemo.java file belongs to a package
package package edu.stanford.nlp.pipeline.demo;
public class StanfordCoreNlpDemo {
public static final void main(String[] args) throws IOException {
// code goes here
}
}
Then calling the following results in Error: Could not find or load main class TheClassName.
java -cp . StanfordCoreNlpDemo
It must be called with its fully-qualified name:
java -cp . edu.stanford.nlp.pipeline.demo.StanfordCoreNlpDemo
And this edu.stanford.nlp.pipeline.demo directory must exist in the classpath. In this example, ., meaning the current directory, is the entirety of classpath. Therefore this particular example must be called from the directory in which edu.stanford.nlp.pipeline.demo exists.
Reference
https://stackoverflow.com/a/29331827/5352399
https://stackoverflow.com/a/18093929/5352399
I am a new beginner of Java. I wrote a Hello.java file with a extend jar package "algs4.jar"(my textbook asked me to use their own output/input library(Algorithm 4th Edition)), which can print a 'Hello,World!\n' string on the shell when executed.
It was compiled without any error, (command:javac -cp E:\AlgorithmExercise\lib\algs4.jar E:\AlgorithmExercise\codes\Hello\Hello.java)
but when I tried to run the class (command: java codes.Hello.Hello), I got this error.
I guessed the reason of this error is because I forgot to enter the path of the algs4.jar package. so I modified the command: java -cp .;E:\AlgorithmExercise\lib\algs4.jar codes.Hello.Hello, but the terminal informed me that it "cannot find or load the main class."
I am absolutely cannot understand what's going on, my classpath has no mistake on configure.
I want to run a java project in terminal. When I compiled, no error occurred, but when I run the program I get the following error:
Could not find or load main class orException in thread "main"
java.lang.NoClassDefFoundError: Appium (wrong name:
com/appiumproj/test/Appium)
Please help me to solve this problem.
iMac:~ Samuel$ javac -cp /Users/Samuel/Downloads/AppiumTest/lib/selenium-server-standalone-2.45.0.jar:/Users/Samuel/Downloads/AppiumTest/lib/gson-2.3.1.jar:/Users/Samuel/Downloads/AppiumTest/lib/java-client-2.2.0.jar: /Users/Samuel/Downloads/AppiumTest/src/com/appiumproj/test/Appium.java
iMac:~ Samuel$ java -cp /Users/Samuel/Downloads/AppiumTest/lib/selenium-server-standalone-2.45.0.jar:/Users/Samuel/Downloads/AppiumTest/lib/gson-2.3.1.jar:/Users/Samuel/Downloads/AppiumTest/lib/java-client-2.2.0.jar: /Users/Samuel/Downloads/AppiumTest/src/com/appiumproj/test/Appium
Error: Could not find or load main class .Users.Samuel.Downloads.AppiumTest.src.com.appiumproj.test.Appium
iMac:~ Samuel$
You need to specify the name of the class - not a filename. It needs to be the fully-qualified class name, and it needs to be on the classpath. So after compiling, you'd want something like this (just spread out on multiple lines for readability; the backslashes are line continuations - you should be able to copy and paste this straight into your shell):
java -cp /Users/Samuel/Downloads/AppiumTest/lib/selenium-server-standalone-2.45.0.jar\
:/Users/Samuel/Downloads/AppiumTest/lib/gson-2.3.1.jar\
:/Users/Samuel/Downloads/AppiumTest/lib/java-client-2.2.0.jar\
:/Users/Samuel/Downloads/AppiumTest/src \
com.appiumproj.test.Appium
Are you sure your compiled version is in /Users/Samuel/Downloads/AppiumTest/src/com/appiumproj/test/ ? I would say that it is probably where the javac was run. Check and find it and specify the path to to compile version
i am trying to execute a java program from command prompt.
On executing the below command the error - Error: Could not find or load main class is seen. The command includes the path to jar files and also path to out folder where class files are present. The same program is working fine in Intellij though.
[root#abc TagPackage]# java -cp "/home/admin/TagAPI/out/production /TagAPI/TagPackage/*":"/home/admin/TagAPI/lib/*" Test3
Error: Could not find or load main class Test3
The structure of my program is as below :
TagAPI> src> (Package)TagPackage> Test3.java
Any suggestion will be helpful, Thanks!!