How to set classpath: first click "My Computer"; then select "Properties" and find "Environment Variables" in "Advanced Settings"; then create a new CLASSPATH variable in the system variables inside. .
How to set classpath in Java: Click "My Computer" and select "Properties" to find "Environment Variables" in "Advanced Settings". Create a new CLASSPATH variable in the system variables, where the variable name should be capitalized, and the variable value is the location of java.class
1. Before understanding the CLASSPATH variable, we must first set the two environment variables JAVA_HOME and path to let JAVA The environment can be successfully run before setting the CLASSPATH.
2. Function: After configuring the CLASSPATH environment, the java command searches for class files according to the path in the CLASSPATH variable. You do not need to locate the path where the java.class file is located to run java. class.
3. When the classpath environment is not set, because HelloWorld is not on the C drive, an error will be displayed, saying that the main class cannot be found or cannot be loaded, and the file where it is located must be located before it can be run.
4. After setting the classpath environment, even if java.class is not in the C drive, it can still run as usual, because after configuring the CLASSPATH environment, the java command follows the path in the CLASSPATH variable. Come to find class files.
The virtual machine goes to the CLASSPATH path to find the HelloWorld.class file
5. Configuration method
(1) The previous opening steps are the same as Set the path to the same path, right-click My Computer - Properties - Advanced Settings - Environment Variables
(2) After clicking the environment variables, click New
in the system variables (3 ) fill in as shown in the picture below. Note that the top and bottom are input by yourself. The variable name is in capital letters and the variable value is where java.class is located.
Note: It is CLASSPATH. Do not type the wrong letters
6. If the location of the HelloWorld.class file is changed and it is not under the path E:\Java\jdk-10.0.2, the following situation will occur
That is, the current path cannot be used, but if you want the current path to still be usable, what should you do?
(1) You can double-click the part pointed to under the picture under CLASSPATH
(2) You can add multiple paths. If the current HelloWorld.class is in E:\ If under the Java path, you can
Note: The semicolon in the picture below is half-width, not full-width. Half-width refers to the semicolon in English, and full-width refers to cents in Chinese. No.;
After that, you can run HelloWorld.class normally
The above is the detailed content of How to set classpath in Java. For more information, please follow other related articles on the PHP Chinese website!