The role of classpath is in one sentence: used to find .class files. For example, if a class references import java.util.List, it will look for List.class in the classpath/java/util directory. As for whether it is "/" or "\", it varies depending on the system
First set the value of the environment variable classpath to ".;f:/" (the current directory and the root directory of the f disk)
Scenario 1: There is the Test.java class in the f:/ root directory, enter the directory f: in cmd, and compile it with javac. After that, calling java Test in any directory in cmd can be successful
Scenario 2: In the f:/path1 directory, there is a parent class SuperClass (the package name of the class is path1), enter the directory, compile to get SuperClass.class, and in the f:/path2 directory, there is a subclass SubClass that inherits SuperClass (import path1.SuperClass) , compiling SubClass in this directory will automatically find SuperClass.class in path1 under f: and compile successfully
Scenario 3: After running java SubClass in f:/path2 successfully
The author had some problems during the test. At the beginning, I set the classpath to ".;f:", and there will be problems in the first scenario. For example, in cmd, I first enter the f:/path1 directory to call java Test successfully, and then enter d: failed to call. Looking for the reason, I found that a phenomenon of cmd first entered f:/path1, then used c: to cut to the c drive, and then used f: to cut to the f drive, and found that the entered directory was f:/path1. I think it has something to do with this. Then add a "/" after the value of classpath, the problem is solved
In the web project, the classpath is the classes directory under WEB-INF. The compiled class files of the java files under src in eclipse will be placed here, and the xml and other files will also be copied to the classpath. There is a default output folder in the right-click project bulid path in eclipse, which is generally xxx/build/classes. This is where eclipse places the compiled files