Reputation: 21
I am trying to run a java file in the cmd prompt in Windows 7.
I get the error:
Error: Could not find or load main class
I actually just save a new simple file to check if there were problems with the package inside eclipse; this new file is saved just as:
C:\Users\User5\Documents\eclipse\test\Example.java
class Example {
// A Java program begins with a call to main().
public static void main(String args[]) {
System.out.println("Test.");
}
}
I changed the classpath
for lucene's jar's recently, and I am not really sure if this is the problem.
There are many other threads about this issue, such as:
Could not find or load main class
but, there seem to be other concerns that solved their issues.
In this case, I have saved just a plain file in notepad, and while I can get the file to compile, and it seems to create the class file, it is still spitting this error back.
This is the dir, which seems to show that the class is there:
C:\Users\User5\Documents\eclipse\test>dir
Volume in drive C has no label.
Volume Serial Number is 3E0D-3B82
Directory of C:\Users\User5\Documents\eclipse\test
12/07/2015 10:15 AM <DIR> .
12/07/2015 10:15 AM <DIR> ..
12/07/2015 10:04 AM 301 .classpath
12/07/2015 10:04 AM 380 .project
12/07/2015 10:04 AM <DIR> .settings
12/07/2015 10:05 AM <DIR> bin
12/07/2015 10:51 AM 428 Example.class
12/07/2015 10:15 AM 162 Example.java
12/07/2015 10:05 AM <DIR> src
4 File(s) 1,271 bytes
5 Dir(s) 10,000,461,824 bytes free
C:\Users\User5\Documents\eclipse\test>java Example.java
Error: Could not find or load main class Example.java
Upvotes: 0
Views: 1760
Reputation: 1
I got the same error when I needed to take inputs(arguements) at runtime using terminal/Command prompt and corrected it it by compiling and running the java class as below:
NOTE: The reason for this error in my case was that the java class was created inside a package and that required compilation and execution in a different way as above mentioned.
Upvotes: 0
Reputation: 53713
C:\Users\User5\Documents\eclipse\test>java Example.java
will not run - take out the .java part and simply run
C:\Users\User5\Documents\eclipse\test>java Example
To make sure you do not have an issue with your CLASSPATH
variable, do
set CLASSPATH=
java Example
If that is the issue, your classpath variable gets corrupted, you can go to the Control Panel, somewhere in the advanced section to update environment variables.
Upvotes: 0
Reputation: 21
I think I need to make this in a larger post:
C:\Users\User5\Documents\java\test>java Example Error: Could not find or load main class Example
I just accidentally posted the wrong copy to the original post here, but the file is not running as just a call to the file. This is not the only file I cannot get running; nothing will run in the cmd prompt, although everthing runs fine in eclipse.
Thank you'all for your help, I really appreciate you!!
Upvotes: 1
Reputation: 13858
This should to the trick - don't append .java
C:\Users\User5\Documents\eclipse\test>java Example
Upvotes: 1