Java CLASSPATH (1) Classpath Basics

Source: Internet
Author: User

 

 

Abstract:
==========================================
On the surface, Java classpath is very simple, but it has always been the root cause of problems and chaos. This article introduces the basic knowledge and possible problems of classpath, and provides a simple classpath management tool.
==========================================
Body:
==========================================

When dealing with Java classpath, developers may encounter occasional troubles. This is because it is sometimes not obvious which class the classloader actually loads. When the classpath of an application contains a large number of classes and directories, the situation is particularly serious. This article provides a tool that displays the absolute path name of the mounted class file.

I. Classpath Basics

The Java Virtual Machine (JVM) uses the class loader to load the classes used by the application. The classes to be loaded are determined based on the current needs. The CLASSPATH environment variables tell the Class Loader where to look for third-party classes and user-defined classes. In addition, you can use the JVM command line parameter-classpath to specify the class path for the application, and the class path specified in-classpath overwrites the value specified in the CLASSPATH environment variable.

The content in the class path can be: the producer file or. jar file ). On Unix systems, projects in the classless path are separated by colons. On MS Windows systems, they are separated by semicolons.

The class loader is organized as a delegate level. Each class loader has a parent class loader. When a class loader is required to load a class, it delegates the request to its parent class loader before trying to find the class itself. System class loader, which is the default Class Loader provided by JDK or JRE installed on the system, use the CLASSPATH environment variable or the-classpath JVM command line parameter to load a third-party class or user-defined class. The system class loader delegates the Extension class loader to load classes that use the Java Extension mechanism. The extended class loader entrusts the bootstrap class loader to load the core JDK class.

You can develop a special class loader to customize how the JVM dynamically loads classes. For example, most Servlet engines use custom class loaders to dynamically load classes that change in the directory specified by classpath.

Note (and surprisingly) that the order in which the Class Loader loads classes is the order in which the classes appear in classpath. The Class Loader starts from the first entry of classpath, checks Each Set directory and compressed file in sequence, and tries to find the class file to be loaded. When the class loader finds a class with a specified name for the first time, it loads the class, and all the remaining items in the classpath are ignored.

It looks simple, right?

 

 

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.