Why JDK CLASSPATH environment variables need to be set Rt.jar and Tools.jar

Source: Internet
Author: User
Tags bootstrap classes

How Classes are Found: (Java Startup class file in Rt.jar, and tool class file in Tools.jar)

How the Java Launcher finds Classes

The Java launcher,  Java , initiates the Java virtual machine. The virtual machine searches for and loads classes with: Bootstrap classes  -classes that C Omprise the Java platform, including the classes in  Rt.jar  and Several other important jar file S. Extension classes  -classes that use the Java Extension mechanism. These are are bundled as .jar files located in the extensions directory. User Classes  -classes defined by developers and third parties, does not take advantage of the EXT Ension mechanism. You identify the location of this classes using the -classpath option on the command line (the preferred method ) or by using the CLASSPATH environment variable. (see  Setting the Classpath  for windows or unix.)

In effect, this three search paths are joined to form a simple class path. This is similar to the "flat" class path previously used, but the ' current model has some ' important differences:it is RelA Tively difficult to accidentally "hide" or omit the bootstrap classes. In general, you have have to specify the location of user classes. Bootstrap classes and extension classes are found "automatically". The tools classes are now separate archive (Tools.jar) and can only is used if included in the user cl Ass path (to be explained shortly). how the Java Launcher finds Bootstrap Classes

Bootstrap classes are the classes that implement the Java 2 Platform. Bootstrap classes are in the Rt.jar and several other jars files in the Jre/lib directory. These archives are specified by the value of the bootstrap class path which are stored in the Sun.boot.class.path system PR Operty. This is a for reference only, and should isn't be directly modified.

It is very unlikely this you'll need to redefine the bootstrap class path. The nonstandard option, -xbootclasspath, allows in those rare cicrcumstances in which it is Necessar Y to use a different set of core classes.

Note This classes which implement the Java 2 SDK tools are in a separate archive from the bootstrap classes. The Tools archive is the SDK ' S/lib/tools.jar file. The development tools add this archive to the user class path when invoking the launcher. However, this augmented user class path are only used to execute the tool. The tools that process source code, javac and Javadoc, with the original class path, not the augmented ve Rsion. (For more information, Javac and Javadoc find Classes, below.)

How the Java Launcher finds user Classes (Java initiator How to find the users Class)

The User classes are classes which build on the Java platform. To find user classes, the launcher refers to the user class path--a list of directories, JAR archives, and ZIP archives which contain class files.

A class file has a subpath name that reflects the class ' s fully-qualified name. For example, if the class com.mypackage.MyClass is stored under/myclasses, then/myclasses must as in the user class path and the full path to the class file must be/myclasses/com/mypackage/myclass.class. If The class is stored in a archive named Myclasses.jar, then Myclasses.jar must be in the user class path, and the class The file must is stored in the archive Ascom/mypackage/myclass.class.

The user class path is specified as a string, with a colon (:Separating the class path entries on Solaris, and a semi-colon (;) Separating entries on Microsoft Windows systems. TheJavaLauncher puts the user class path string in the Java.class.path system property. The possible sources of this value are:the default value, ".", meaning that user class files are all the class files in the current directory (or under it, if in a package). The value of theCLASSPATHenvironment variable, which overrides the default value. The value of the-CPOr-classpathCommand line option, which overrides both the default value and theCLASSPATHValue. The JAR archive specified by the-jaroption, which overrides all other values. If This option is used, all user classes must come from the specified archive.

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.