[problem description]
User root is created in the/root/exercise folder HelloWorld.java The code is as follows:
Compile and run the file as follows:
Compile HelloWorld.java Generate bytecode file HelloWorld.class , running HelloWorld.class 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 class in the current directory.
[solution]
Step 1: add the classpath system variable at the end of the profile file in/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: input source/etc/profile on the command line to make the system variables in/etc/profile effective and then run.
Note: you can modify system variables only if the current user is root. If you enter source/etc/profile on the command line, the system variable will only take effect temporarily. If you close terminal, the system variable will be restored to its original state. Because the system variable is loaded at system startup, the system variable will be loaded automatically only at the next system restart, so you don’t need to enter source/etc/profile again.
The results are as follows
Read More:
- Java error: unable to find or load main class (package name in source file)
- Java uses class array to report error Exception in thread “main” java.lang.NullPointerException solution
- [Solved] Maven Project Packaging Error: Unable to find main class
- Gephi cannot find Java 1.8 or higher [How to Solve]
- Problems and causes of Java’s main function format (public static void main (string args()))
- [Solved] IDEA Error(15, 16) java Program Pack sun.misc does not exsit or import sun.misc.BASE64Decoder Cannot find
- java: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x590
- JAVA Error Illegal access: this web application instance has been stopped already. Could not load net.sf
- [Solved] Hbase-shell 2.x Error: Unhandled Java exception: java.lang.IncompatibleClassChangeError: Found class jline.Terminal…
- Nacos boot error, unable to find Java_HOME [How to Solve]
- [Solved] Failed to load class org.slf4j.impl.StaticLoggerBinder
- [Solved] Cannot find class: com.mysql.jdbc.Driver
- [Solved] Initialization of anonymous inner class member variable causes java.lang.stackoverflowerror
- How to Solve Java Runtime (class file version 53.0)ERROR
- [Solved] Docker Elasticsearch8.4.0 Error: Exception in thread “main” java.nio.file.FileSystemException
- Java will convert Excel to list set or JSON, export excel file to local, excel import and export, easyexcel tool class
- Maven project running servlet jump JSP error: HTTP status 500 – unable to compile class for JSP
- Java Error: No enclosing instance of type Main is accessible. Must qualify the allocation with an encl
- DevTools failed to load SourceMap Could not load content [Solved]
- [Solved] Mapreducer Class Conversion error: java.lang.ClassCastException