The role of classpath, Path, java_home and the configuration of JAVA environment variables

Source: Internet
Author: User

What is Classpath? What is the role of it?

It is an environment variable of the Javac compiler. Its role is related to import, the package keyword. When you write down Improt java.util.*, when the compiler faces the import keyword, you know you want to introduce java.util the class in the package, but how does the compiler know where you put the package? So you first have to tell the compiler where the package is located, and how do you tell it? is to set classpath:) If java.util this package in the c:/jdk/directory, you have to set c:/jdk/this path to Classpath! When the compiler faces the import java.util.* this statement, it first looks for the directory specified by Classpath and checks to see if the subdirectory java/util exists, and then finds the compiled file (. class file) that matches the name. If you do not find it will be an error! Classpath is a bit like the include path setting in the C + + compiler Oh, isn't it? When a C + + compiler encounters a statement such as include, how does it work? Oh, the truth is almost the same! Search the Include path to view the file! When you develop a package yourself, and then want to use the class in the package, naturally, you also have to set the directory where the package resides in Classpath! Classpath's setting is a tricky thing for beginners in Java. So Sun made JAVA2 's jdk a little bit smarter. You will find that after you install, you can still compile the basic Java program and execute it even if you have not set classpath at all.

......................................................................................................................... ............................

1. Path environment variable. The function is to specify the command search path, execute the command below the command line, such as Javac compiling the Java program, it will look in the path specified by the paths variable to see if the corresponding command program can be found. We need to add the bin directory in the JDK installation directory to the existing path variable, and the bin directory contains the frequently used executables such as Javac/java/javadoc wait, and after setting the path variable, you can execute the Javac/java tool in any directory. The path value we set here is:

%systemroot%/system32;%systemroot%;%systemroot%/system32/wbem;%systemroot%/system32/windowspowershell/v1.0/; C:/Program Files/common Files/thunder network/kankan/codecs; C:/Program Files/microsoft SQL server/90/tools/binn/; C:/Program Files/common Files/ttkn/bin; C:/Program Files/common Files/teleca gkfx; C:/Program Files/java/jdk1.6.0_21/bin

Only the red ones above; C:/Program Files/java/jdk1.6.0_21/bin is the path variable of Java, note that the variables need to be used ";" Separated.

2. CLASSPATH environment variables. The role is to specify the class search path, to use the already written classes, the premise is to be able to find them, the JVM is through the classpath to find the class. We need to set the Dt.jar and Tools.jar in the Lib subdirectory of the JDK installation directory to classpath, of course, the current directory "." must also be added to the variable. Here classpath is:

.; C:/Program Files/java/jdk1.6.0_21/lib/dt.jar; C:/Program Files/java/jdk1.6.0_21/lib/tools.jar

3. Java_home environment variables. It points to the JDK's installation directory, and software such as Eclipse/netbeans/tomcat finds and uses the installed JDK by searching for java_home variables. Here Java_home is:

C:/Program files/java/jdk1.6.0_21

......................................................................................................................... ............................

Java environment variable configuration steps:

On the Windows desktop, right-click "My Computer", "Properties", "Advanced", "Environment variables", in "system variables" we can see the values of the system's various environment variables. Double-click a variable name to modify the value of the variable, using ";" between the variable values. Separated. We can also "create new" variables that were not previously available. There are 3 environment variables associated with the JDK, "Java_home", "PATH", "CLASSPATH". The "PATH" variable already exists in my system, can add the new value directly (other variable values do not move, prevent other programs to run the exception), the other two variables need to be new.

Classpath=.; %java_home%/lib/dt.jar;%java_home%/lib/tools.jar

Java_home = C:/Program files/java/jdk1.5.0

PATH =%java_home%/bin;%java_home%/jre/bin

As we can see from the above, both path and classpath are used in java_home, and absolute paths can be used, either.

The role of classpath, Path, java_home and the configuration of JAVA environment variables

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.