Three environment variables (java_home, classpath, and Path) that need to be set frequently in Java)

Source: Internet
Author: User

Three environment variables that need to be set frequently in Java:
Java_home, classpath, path
(1) Configure environment variables: (relative path)
1.
Java_home = x:/jdk1.6.0
2.
% Java_home % can replace: X:/jdk1.6.0.
Classpath =.: $ java_home/lib/tools. jar: $ java_home/lib/dt. jar: $ java_home/lib/activation. jar: $ java_home/lib/mail. Jar
Or
Classpath =./; % java_home %/lib/tools. jar; % java_home %/lib/dt. Jar
3.
Path =.; % java_home %/bin
(2) Configure environment variables: (absolute path)
1.
Java_home = D:/jdk1.5.0
2.
Classpath =.; D:/jdk1.5.0/lib/tools. jar; D:/jdk1.5.0/JRE/lib/RT. jar;
3.
Path = D:/jdk1.5.0/bin;

(3)
Run the following code in batches, which is convenient for setting environment variables.

@ Echo off
If exist % 1/bin/java.exe (
If REM enters the correct java2sdk installation directory, it starts to set environment variables.
@ Setx java_home % 1
@ Setx PATH %; % java_home %/bin
@ Setx classpath % ;.
@ Setx classpath %; % java_home %/lib/tools. Jar
@ Setx classpath %; % java_home %/lib/dt. Jar
@ Setx classpath %; % java_home %/JRE/lib/RT. Jar
@ Echo on
@ Echo Java 2 SDK environment parameters are set and exit normally.
) Else (
If "% 1" = ""(
If the installation directory is not provided by REM, exit after prompt
@ Echo on
@ ECHO does not provide the installation directory of java2sdk, and does not set anything. Now exit the environment variable settings.
) Else (
Rem if non-empty installation directory is provided but no bin/java.exe is available, the specified directory is the wrong directory.
@ Echo on
@ ECHO: the installation directory of the invalid java2sdk is not set. Now exit the environment variable settings.
)
)

(4) Other Practices
CMD command settings
Set Path = C:/j2sdk1.4.0/bin

Note:
Java_home: The software depends on this variable to find the JDK installation directory. If this variable is not set, the software package can hardly find where javac.exe is. This environment variable is used to determine the path of javac.exe to execute compile tasks. The value of this environment variable is your JDK installation directory. If your JDK is installed in C:/jdk1.42, "C:/jdk1.42" is the value of java_home.
Classpath: A class path that tells the Java application where to find third-party and custom classes-that is, classes that are not part of Java extensions or Java platforms. In JDK 1.2, JVM and other JDK tools search for classes by platform libraries, library extensions, and class paths (for more information about search policies, see how to find classes ). Most application class libraries make full use of the extension mechanism. Therefore, you must set a class path only when you want to load a class library (a) that is not in the current directory or its branch package and (B) that is not in the position specified by the extension mechanism. In addition to paths, the classpath list can also contain. Jar files. The. jar file is used as a directory to search for classes in Java. Generally, we need to include JRE/lib/RT. Jar (Linux: JRE/lib/RT. Jar) in the JDK installation path in classpath.
Path: Specifies a path list for searching executable files. When executing an executable file, if the file cannot be found in the current path, find each path in the path in sequence until it is found. Or if the path in the path cannot be found, an error is returned. Java compilation commands (javac), execution commands (Java), and some tool commands (javadoc, jdb, etc.) are all in the bin directory under the installation path. Therefore, we should add this path to the PATH variable.

Path and classpath both specify the path list. The items in the list (that is, each path) are separated by separators. In Windows, the Delimiter is a semicolon (;), while in Linux, The Delimiter is a colon (:).

Related Article

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.