Java environment variable configuration method

Source: Internet
Author: User
Tags requires

To configure JDK environment variables under Windows XP:

1. Installation of JDK, installation process can be customized to install the directory and other information, such as our choice of installation directory for d:javajdk1.5.0_08;

2. After the installation is complete, right click on "My Computer", click "Properties";

3. Select the "Advanced" tab and click "Environment variable".

4. In "System Variables", set 3 properties, Java_home,path,classpath (regardless of the case), if already exist click "Edit", does not exist then click "New";

5.java_home indicates the JDK installation path, which is the path you chose when you just installed d:javajdk1.5.0_08, including Lib,bin,jre folders under this path (this variable is best set, since Tomcat,eclipse will need to follow * this variable);

Path enables the system to identify Java commands under any path, set to:

%java_home%bin;%java_home%jrebin

Classpath is the Java load class (class or Lib) path, and only classes in Classpath can be recognized by Java commands, set to:

.; %java_home%libdt.jar;%java_home%libtools.jar (to be added. Represents the current path)

%java_home% is a reference to the java_home specified above;

6. "Start the->;" Run ", type" cmd ";

7. Type the command "Java-version", "Java", "Javac" several commands, appear screen, indicating the success of environment variable configuration;

8. All right, finish the call. Let's start with your first Java program.

Win7 Java environment variable settings and Java programming tool installation Please refer to: http://www.pc6.com/infoview/Article_52980.html

The meaning of several Java environment variables and the configuration method under Linux are as follows:

Typically, we need to set three environment variables: java_home, PATH, and CLASSPATH.

Java_home: The value of this environment variable is the directory of Java, some Java software and some Java tools need to use this variable, set PATH and CLASSPATH, you can also use this variable for easy setting.

Path: Specifies a list of paths to search for executable files. When executing an executable file, if the file cannot be found under the current path, then look for each path in the path until it is found. Or you cannot find the path in the paths you are looking for, an error occurs. The Java Compilation command (JAVAC), execution commands (Java), and some tool commands (Javadoc, JDB, etc.) are in the Bin directory under their installation path. So we should add it to the path variable.

CLASSPATH: also specifies a list of paths that are used to search for Java compilation or runtime classes that need to be used. In the CLASSPATH list, you can include the. jar file in addition to the path. Java Lookup classes will look at this. jar file as a directory. Typically, we need to include the Jrelibrt.jar (Linux:jre/lib/rt.jar) under the JDK installation path in CLASSPATH.

Both path and CLASSPATH specify a list of paths, separated by delimiters between the items in the list, that is, the individual paths. Under Windows, delimiters are semicolons (;), and in Linux, delimiters are colons (:).

Here's how three environment variables are set up under Windows and Linux, but before we do, we need to make a hypothesis. Assuming that the JDK installation path under Windows is C:JDK, the installation path under Linux is/usr/local/jdk/. Then, the installed JDK will at least include the following:

C:JDK (/USR/LOCAL/JDK)

|--Bin

|-| demo

|--Include

|--JRE

| | |-bin

| '--Lib

'--Lib

Set under Windows

Windows uses the SET command to set environment variables, and for each startup computer to set these environment variables, you should set them in the Autoexec.bat file in the system's packing directory, such as:

Set JAVA_HOME=C:JDK

Set Path=%java_home%bin; C:windows; C:windowscommand

Set Classpath=%java_home%jrelibrt.jar;.

Some versions of Windows cannot replace the contents of the environment variable with the% variable name%, so you have to write c:jdk instead of%java_home%. In addition, C:windows and C:windowscommand are the paths that Windows automatically joins, so they can be removed from the settings. If path is already set in Autoexec.bat, it is only necessary to add%java_home%bin to the statement that originally set path.

CLASSPATH can also be set or add other paths as needed, such as you want to write some of the classes in the C:java, you can add C:java also to CLASSPATH, set classpath=%java_home% Jrelibrt.jar; C:java;

Note that a "current directory (.)" is included in the CLASSPATH. Once the directory is included, you can go to any directory to perform a Java program that requires a class in that directory, even if the path is not included in the CLASSPATH. The reason is simple: although there is no explicit inclusion of the path in CLASSPATH, the "." In CLASSPATH represents the path at this point, such as:

Assuming that there is a C:java class Hellojava.class in the directory, then

C:> set Classpath=c:jdkjrelibrt.jar;. Set the CLASSPATH environment variable, note that the last one is "."

C:> CD Java//go to C:java directory

c:java> Java Hellojava//Run Hellojava

Hello, Java. Run results

c:java> _

Set up under Linux

Use the variable name = variable value under Linux to set the variable and export it as an environment variable using the Export command. In order for each login to automatically set these variables, you need to set them in ~/.bash_profile or ~./BASHRC, such as

Export JAVA_HOME=/USR/LOCAL/JDK

Export path= $JAVA _home/bin: $PATH

Export classpath= $JAVA _home/jre/lib/rt.jar:.

The $JAVA _home used to set up PATH is the value of the replacement variable Java_home to the location of the $JAVA _home. As the last sentence is actually export path=/usr/local/jdk/bin: $PATH. $PATH is the same in this sentence, but the path here refers to the value of the path variable that was previously set, not the value of the path variable this time.

Note that a "current directory (.)" is included in the CLASSPATH. Once the directory is included, you can go to any directory to perform a Java program that requires a class in that directory, even if the path is not included in the CLASSPATH. The reason is simple: although there is no explicit inclusion of the path in CLASSPATH, the "." In CLASSPATH represents the path at this time, for example

Assuming that there is a/home/fancy/java class Hellojava.class in the directory, then

[Fancy@matrix fancy]$ export Classpath=/usr/local/jdk/jre/lib/rt.jar:. Set CLASSPATH, pay attention to the last "."

[Fancy@matrix fancy]$ CD ~/java//Go to/home/fancy/java

[Fancy@matrix java]$ pwd//Display current directory

/home/fancy/java//Current directory is/home/fancy/java

[Fancy@matrix java]$ Java Hellojava//Run Hellojava

Hello, Java//Run Results

[Fancy@matrix java]$ _

Analysis

Example analysis

Only the operating system is different, a slight difference.

Two examples refer to a "running class", which refers to a class that contains the public static void main (string[] args) method, which is detailed in the next Chapter Hellojava section. The CLASSPATH in the example does not contain the directory where the Hellojava.class resides (C:java,/home/fancy/java), but contains the current directory (.). So go to the directory that contains the Hellojava.class to execute the Java Hellojava, in Java looking for CLASSPATH. (current directory, C:java,/home/fancy/java) "When found Hellojava.class, run successfully.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.