Set class Path

Source: Internet
Author: User
Tags command line switches zip

Structure

You can set the Classpath by using the-classpath option (preferred method) or by setting the CLASSPATH environment variable for the JDK tool.

C:>jdktool-classpathpath1;path2 ...

C:>setclasspath=path1;path2 ...

Each path ends with a file name or directory, which depends on what the classpath is set to:

For a. zip or. jar file that contains a. class file, the path ends with a. zip or. jar file name.

For the. class file in the unnamed package, the path ends with the directory that contains the. class file.

For the. class file in the named package, the path ends with the directory containing the "root" package (the first package in the full package name).

Separate multiple items with semicolons. When you use the SET command, you omit the space (=) on either side of the equal sign. Where jdktool can be Java, Javac, Javadoc, and so on. For a detailed list, see JDK development tools.

Description

The classpath tells the Java application where to look for Third-party and custom classes-classes that are not part of a Java extension or a Java platform. In JDK1.2, the JVM and other JDK tools find classes by searching the Platform library, library extensions, and classpath in turn (For more information about search policies, see how to find classes).

The class libraries of most applications take full advantage of the extension mechanism. Therefore, you only need to set the classpath if you want to load a class library (a) that is not located in the current directory or its branch package and (b) is not located at a location specified by the extension mechanism.

If the user is upgraded from an older version of the JDK, the startup settings may include classpath settings that are no longer needed. You should remove any non-application-specific settings at this time. Some third-party applications that use Java virtual machines may modify the CLASSPATH environment variables to include the class libraries they use. This setting can be preserved.

You can change the classpath (for example, Java-classpath ...) by using the Java tool's-classpath option when invoking the JVM or other JDK tools. )。 This is the preferred method of changing the classpath. You can also change the classpath by using the CLASSPATH environment variable.

Note: The JDK1.2 default class path is the current directory. Setting the CLASSPATH variable or using the-classpath command line switch overrides the default value, so if you want to include the current directory in the search path, you must include the "." in the new setting.

A class can be stored in a directory (folder) or archive (such as Classes.zip or Classes.jar). For more information about the archive and how the Classpath works, see the final understanding of the Classpath and package name in this document.

Important: The JDK old version also includes the <jdk-dir>/classes entry in the default classpath. This directory is intended for JDK use only and is not intended for application classes. Application classes should be placed in directories outside the JDK. This eliminates the need to reinstall the application library when installing a new JDK. For compatibility with older versions, applications that use the <jdk-dir>/classes directory as class libraries can still run in the current version, but they are not guaranteed to run in future releases.

-classpath options for using Java tools

Java tools Java, Jdb, Javac, and Javah have the-classpath option, which replaces the default classpath or the classpath specified by the CLASSPATH environment variable when the tool is run. This is a recommended way to change the classpath settings because each application can have the classpath it needs without interfering with other applications.

Runtime tools Java and Jdb also have-CP options. This option is an abbreviation for-classpath.

For very special situations, both Java and Javac have switches that allow them to change the paths they use to find their own class libraries. However, most users never use these switches.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.