Why does this work in executing my code:
java -cp . Main
but not this:
java Main
I have always used just java <classname>
for executing my code, however almost randomly, this command just provides the error message Error: Could not find or load main class Main
.
Here's my Java file (Main.java):
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Here's the output from my Command Prompt including file names
java Main
would not work? – Justin Vos Sep 27 '16 at 13:17CLASSPATH
environment variable. If that's specified, then it's used; and if it doesn't contain.
, then you have to explicitly specify on the command line. – Marko Topolnik Sep 27 '16 at 13:21CLASSPATH
environment variable, and I didn't already have it included. However, it results in the sameError: Could not find or load main class Main
with justjava Main
. Thanks for the help anyway :) – Justin Vos Sep 27 '16 at 13:28