CLASSPATH Environment Variable
The CLASSPATH environment variable specifies the system’s default location for .class files. Java compilers (JVC), application viewers (https://msdn.microsoft.com/en-us/library/aa266196(v=vs.60).aspx and https://msdn.microsoft.com/en-us/library/aa266198(v=vs.60).aspx ), and virtual machines use the information stored in the CLASSPATH environment variable when compiling and running Java programs. When compiling from the command line, use the /cp:p and https://msdn.microsoft.com/en-us/library/aa265235(v=vs.60).aspx to add information to the CLASSPATH environment variable.
Note The option settings for JVC, https://msdn.microsoft.com/en-us/library/aa265386(v=vs.60).aspx , and https://msdn.microsoft.com/en-us/library/aa266234(v=vs.60).aspx apply only to the current compilation and must be entered each time these tools run.
Setting the CLASSPATH environment variable from the command line changes it permanently until the system shuts down. However, the /cp, /cp:p, and /cp:a options of JVC, JVIEW, and WJVIEW can replace or modify the CLASSPATH environment variable when compiling and viewing your Java programs.
Note The directories in the CLASSPATH environment variable are separated by semicolons on a Microsoft Windows system.
The following syntax sets the CLASSPATH environment variable from the command line:
SET CLASSPATH = <path>
CLASSPATH and the Java Package Manager (JPM)
When the VM installs, it registers information about all Java packages with the Java Package Manager (JPM) and enters the following CLASSPATH values into the HKEY_LOCAL_MACHINE\Software\Microsoft\Java VM\Classpath registry key:
|Windows 95||C:\WIN95\java\classes\classes.zip; C:\WIN95\java\classes;.;|
|Window NT||C:\WINNT\java\classes\classes.zip; C:\WINNT\java\classes;.;|
When a Java programs runs, the VM searches for .class files by gathering information from the following sources in the order listed:
Command-line provided paths
Note Use the /cp, /cp:p, and /cp:a options to specify CLASSPATH information when running JVC, JVIEW, and WJVIEW.
The DevClasspath registry key
Note The DevClasspath registry key allows developers who are working on packages to supercede packages that may be installed in the Java Package Manager’s (JPM) database. With this key, developers can build their packages into a specified directory and JPM’s installed packages will not shadow it. For more information about the Java Package Manager, see the documentation.
Java Package Manager (JPM) database
Note When your program runs from within the Visual J++ development environment, the VM includes the information entered into the Java Packages tab of Settings dialog box when searching for .class files. Access the Java Packages tab from the Project menu’s Settings dialog box. For more information on using the Java Package Manager, see the documentation.
The TrustedClasspath, TrustedLibsDirectory, Classpath, and LibsDirectory registry keys
- The CLASSPATH environment variable