Tag Archives: Error: Could not find or load main class

[Solved] JAVA Run Error: Error: Could not find or load main class

Compile helloworld.java to generate the bytecode file helloworld.class, and run helloworld.class with error: could not find or load main class

[cause analysis]

The current directory is the directory where the. Class file is located. To run the. Class bytecode file, you need to add the current directory to the system variable classpath to find the Java classes in the current directory.

The classpath path is entered incorrectly. You need to enter the current path and add.:

[solution]

Step 1: add.:,. In front of the classpath system variable at the end of the profile file under/etc to represent the current path

The classpath in the original/etc/profile file is:

CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

The added classpath is: classpath =.: $Java_HOME/jre/lib/ext:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

Step 2: on the command line, enter source/etc/profile to make the system variables in/etc/profile take effect and run.