Java classpath

The Java™ virtual machine uses the Java classpath to find classes during runtime. Java commands and tools also use the classpath to locate classes. The default system classpath, the CLASSPATH environment variable, and the classpath command parameter all determine what directories are searched when looking for a particular class.

The java.ext.dirs property determines the classpath for the extensions that are loaded. See Installing Java extensions for more information.

The default bootstrap classpath is system-defined, and you should not change it. On your server, the default bootstrap classpath specifies where to find the classes that are part of the IBM® Developer Kit for Java, and other system classes.

Start of changeThe java.endorsed.dirs property is a standard way to override endorsed versions of Java classes by adding JAR files to the bootstrap classpath. See Java Endorsed Standards Override MechanismLink outside Information Center for more information.End of change

To find any other classes on the system, specify the classpath to search by using the CLASSPATH environment variable or the classpath parameter. The classpath parameter that is used on a tool or command overrides the value that is specified in the CLASSPATH environment variable.

You can work with the CLASSPATH environment variable using the Work with Environment Variable (WRKENVVAR) command. From the WRKENVVAR display, you can add or change the CLASSPATH environment variable. The Add Environment Variable (ADDENVVAR) command and Change Environment Variable (CHGENVVAR) command either add or change the CLASSPATH environment variable.

The value of the CLASSPATH environment variable is a list of path names, separated by colons (:), which are searched to find a particular class. A path name is a sequence of zero or more directory names. These directory names are followed by the name of the directory, the ZIP file, or the JAR file that is to be searched in the integrated file system. The components of the path name are separated by the slash (/) character. Use a period (.) to indicate the current working directory.

You can set the CLASSPATH variable in the Qshell environment by using the export utility that is available using the Qshell Interpreter.

These commands add the CLASSPATH variable to your Qshell environment and set it to the value ".:/myclasses.zip:/Product/classes"

The J2SE searches the bootstrap classpath first, then the extension directories, then the classpath. The search order for J2SE, using the previous example above, is:

  1. The bootstrap classpath, which is in the sun.boot.class.path property,
  2. The extension directories, which is in the java.ext.dirs property,
  3. The current working directory,
  4. The myclasses.zip file that is located in the "root" (/) file system,
  5. The classes directory in the Product directory in the "root" (/) file system.

Some Java tools and commands contain a classpath parameter in which a list of path names can be specified. The parameter has the same syntax as the CLASSPATH environment variable. The following list shows some of the tools and commands for which the classpath parameter can be specified:

For more information about these commands, see Java commands and tools. If you use the classpath parameter with any of these command or tools, it ignores the CLASSPATH environment variable.

You can override the CLASSPATH environment variable by using the java.class.path property. You can change the java.class.path property, as well as other properties, by using the SystemDefault.properties file. The values in the SystemDefault.properties files override the CLASSPATH environment variable. For information about the SystemDefault.properties file, see the SystemDefault.properties file.

Start of changeThe -Xbootclasspath option and the java.endorsed.dirs property also affects what directories the system searches when looking for classes. Using -Xbootclasspath/a:path appends path to the default bootstrap classpath, /p:path prepends path to the bootstrap classpath, and :path replaces the bootstrap classpath with path. JAR files located in the directories specified for the java.endorsed.dirs property are prepended to the bootstrap classpath.End of change

Note: Be careful when you specify -Xbootclasspath because unpredictable results occur when a system class cannot be found or is incorrectly replaced by a user-defined class. Therefore, you should allow the system default classpath to be searched before any user-specified classpath.

See Java system properties for information about how to determine the environment in which Java programs run.

For more information, see the Program and CL Command APIs or the Integrated file system.