Java Setting environment variables

Source: Internet
Author: User

the guests turned around. very many people write for a long time Java code, do not know how the environment variable is one thing, science.

A. Java Settings Environment Variables-Lite version 1. Right-click My Computer, Properties---Advanced environment variable 2. New System Variables Java_home and Classpathvariable name (N): Java_homevariable Value (V): C:\Program files\java\jdk1.7.0variable name (N): CLASSPATHvariable Value (V):.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar; 3. Select the environment variable named "Path" in the "System variables" and double-click the variable. Take the absolute path to the Bin folder in the JDK installation path. Added to the value of the path variable. and use the half-width semicolon in English and the existing path to separate. variable name (N): Pathvariable Value (V):%java_home%\bin;%java_home%\jre\bin;  Two, Java Settings environment variable-specific edition after installing the JDK to the computer (here, install it in jdk1.7. Other version numbers), and then set up, the Java environment will take effect.  First, right click on my Computer. Open the property. Then select "Environment variable" inside "advanced", in the new open interface need to set three system variable attribute "Java_home", "Path", "CLASSPATH". Before the JDK was installed, the path attribute was originally present, andJava_home and classpath These two system variables do not exist and need to be created. Click New, and then write the java_home on the variable name (N). The Java_home variable represents the installation path for Java. Then change the measure (N) to write to the path you just installed "C:\jdk1.7". (Note: Assume that the path installed is not disk C or not in the jdk1.7 directory, it can be changed accordingly.) The following words are assumed to be installed inside the C:\jdk1.7. )  Second, find the path in the system variable, then click "Edit", and the path variable indicates that the system can recognize the Java command under no path.

Then change the measure (N) to write ".; %java_home%\bin ". (the "%java_home%" means to set the value of Java_home just now). can also write "C:\jdk1.7\bin" directly. It is recommended to use the former. High reusability. Third, click "New", and then write the Classpath,classpath variable on the variable name to indicate the Java load class or lib path. There are only classes in classpath. Java Command talent recognition. Then change the measure (N) to write ".; %java_home%\lib \dt.jar;%java_home%\lib\toos.jar "(To Add. Indicates the current path) last. The Java Settings environment variable is complete, press OK until the property form disappears, that is, the save successfully verifies that the Java Settings environment variable is successful. Open Start, execute first. Enter "cmd" and go to the DOS system interface.

Then enter "Java-version", assuming the installation was successful. The system displays the Java version jdk "1.7.0". So the Java setting environment variable OK! Summary. Java Setting Environment variables purpose: 1,java_home(1) for the convenience of reference, such as your JDK installed in the C:\Program files\java\jdk1.7.0 folder, then set Java_home as the folder path, then you want to use this path, you just need to enter the%java_home% It is possible to avoid entering a very long path string for each reference;(2) A principle, when you need to change the JDK path, you just have to change the value of the Java_home variable, or you will change whatever the absolute path to refer to the JDK folder document, if you do not change, a program can not find the JDK, the consequences may be a program crash; (3) third-party software will refer to the agreed-java_home variable, before the normal use of the software, after a long time in Java will know that if a software does not work properly, it is likely that the java_home set incorrectly caused.  2,classpathThe purpose of setting up the classpath is to find the corresponding ". Class" File for the program, for example: Compile a Java program---a.java, you will get a A.class class file, run Java A in the current folder, you will get the corresponding result ( The premise is that you have setclasspath is "."). Now, moving A.class to another folder (such as "E:\"), running Java A, will throw a Java.lang.NoClassDefFoundError exception, because the. class file is not found, and now you add Classpath as: ".; E:\ "Execute Java A again, the result is all right, the Java command found the. class file through Classpath!  3. PATHDo you want to run JAVA commands at any time using%java_home%\bin\java and so on, of course not, so you can choose to add%java_home%\bin to the path, so that we can only use JAV for whatever path A to run the command. (When you enter your code in the command prompt form, the operating system looks for the corresponding application in the current folder and path variables folder, and it runs. )  three. Java Setting environment Variables-Error cases Error: Java.lang.NoClassDefFoundErrorDescriptive narrative: When a Java virtual machine or ClassLoader instance attempts to load in the definition of a class (as part of a typical method call or as part of a new instance created with a use new expression). This exception is thrown when the definition of the class cannot be found. Cause: Java Setting environment variable error

Java Setting 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.