Settings and functions of java_home path classpath in Java environment variables

Source: Internet
Author: User


Today, I set the Java environment variable again. I suddenly found that every setting was completed step by step. I didn't know why I needed it. So I searched for it online and found it again.ArticleAnd leave it.
Only for record learning. Transferred from:Http://bbs.tech.163.com/bbs/tech_0ik1/147645925.html

After installing JDK on a computer, we can set it to make it usable in the Java environment. Right-click my computer. Open properties. Then select "environment variables" in "advanced". In the new open interface, you must set three attributes: "java_home", "path", and "classpath ", in this scenario, JDK is not installed. The path attribute already exists. Java_home and classpath do not exist.

I. Click "new" and write java_home in the variable name. The variable meaning is the installation path of Java, then, write the installation path "C: \ jdk1.6" in the variable value ". (Note: If the installation path is not disk C or is not in the jdk1.6 folder, you can modify it accordingly. The following text is assumed to be installed in c: \ jdk1.6 .)
2. Find the path in the system variable and click Edit. The meaning of the PATH variable is that the system can recognize Java commands in any path, and the variable value is ".; % java_home % \ bin "(" % java_home % "indicates the value of java_home just set), or you can directly write" C: \ jdk1.6 \ bin"
3. Click "new" and then write classpath on the variable name. The variable indicates the path of the Java loading class (class or Lib). Only the class is in classpath, java commands can be recognized. The value is ".; % java_home % \ Lib \ DT. jar; % java_home % \ Lib \ toos. jar (to add. indicates the current path) ", which means the same as" % java_home %"

--------Note that the first".\;",--Backslash. This is to tellJDK, SearchClassFirst, findClassFile.

After the preceding three variables are set, press "OK" until the attribute window disappears. verify whether the installation is successful. Open "start"> "run", and press "cmd" to go To the DOS system interface. Then, press "Java-version". If the installation is successful. The system displays Java version JDK "1.6.0 ".
Make sure that the file name on drive C is jdk1.6 and the environment variables can be copied directly. On the DOS interface, enter javac to check whether the command is legal, and enter Java to check whether the command is legal.

In this way, the environment variables are set. The following describes path, classpth, and java_home.

Set java_home, classpath, and path as follows:
1. Set java_home:
1. For reference convenience, for example, if your JDK is installed in the c: \ Program Files \ Java \ jdk1.6.0 directory, set java_home to the directory path, to use this path in the future, you only need to enter % java_home % to avoid entering a long path string for each reference;
Ii. Normalization principle: when your JDK path is forced to change, you only need to change the variable value of java_home. Otherwise, you need to change any document that uses the absolute path to reference the JDK directory, if you haven't completed the changeProgramIf JDK is not found, the system crashes!
3. The third-party software will reference the agreed java_home variable. Otherwise, you will not be able to use the software normally. After using Java for a long time, you will know that if a software cannot be used normally, think about the problem.

2. Set classpath:
This is a very interesting question. Of course, it is also a question that affects beginners. The purpose of this variable setting is to allow the program to find the corresponding ". for example, compile a Java program ---. java,. class class file. If you execute Java A in the current directory, the corresponding result will be obtained (provided that you have set classpath ". "). now. when the class is moved to another directory (for example, "E: \") and Java A is executed, there will be a noclassdeffinderror exception because it cannot be found. class file, now you add classpath :".; e: \ "run Java A again to see what the result will be ~~ :)~~~, Everything is normal. The Java Command finds the. Class file through classpath!

3. Set path:
The principle is very simple. Do you want to use % java_home % \ bin \ Java to execute Java commands at any time? Of course not, so, you can add % java_home % \ bin to the path. In this way, we can use Java to execute commands in any path. (When you enter yourCodeThe operating system will find the corresponding application in the current directory and PATH variable directory and execute.

 

The following situations may occur during compilation to check whether you really understand the settings of environment variables and solve them.

[T1] Error:JavaNot a runable program? The environment variable is not set.Path

[T2] Error:Cannot open a directory? It may be ignored.PathSet the sequence of directories in environment variables.

[T3] exception on thread "main" java. Lang. doclassdeffounderror: Test? Not SetClasspath.

[T4] When the android SDK is installed, the following error occurs: JDK not foundsystem cannot find the specified file java.exe has not set the environment variable path.

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.