ggmm looking for a job , please go to www.ggmmjob.com to cast a resume .....
Configure the JDK environment variables under Windows XP:
1. Install the JDK, the installation process can define the installation folder and other information, such as we choose the installation folder for d:/java/jdk1.5.0_08;
2. After the installation is complete, right click on "My Computer" and click "Properties";
3. Select the "Advanced" tab and click on "Environment variables";
4. In "System Variables", set 3 properties, Java_home,path,classpath (uppercase and lowercase), if already exist then click "Edit", do not exist then click "New";
5.java_home indicates the installation of the JDK path, that is, the path that was selected at the time of installation d:/java/jdk1.5.0_08, this path contains lib,bin,jre such as directory (this variable is the best setting, because after the implementation of tomcat,eclipse and so need to depend on * this variable);
Path allows the system to identify Java commands, regardless of the path, set to:
%java_home%/bin;%java_home%/jre/bin
Classpath is a Java load class or lib path, and there are only classes in Classpath, the Java command talent is recognized, set to:
.; %java_home%/lib/dt.jar;%java_home%/lib/tools.jar (to Add. Indicates the current path)
%java_home% is referring to the previously specified java_home;
6. "Start"->; " Execute ", type" cmd ";
7. Type the command "Java-version", "Java", "Javac" several commands, appear screen, indicating that the environment variable configuration is successful;
8. OK, finish the call. Start your first Java program below.
Here are the meanings of several Java environment variables and the configuration method under Linux:
Typically, we need to set up three environment variables: java_home, PATH, and CLASSPATH.
Java_home: The value of this environment variable is the folder where Java is located, some Java version of the software and some Java tools need to use the variable, set PATH and CLASSPATH, you can also use this variable to facilitate setup.
Path: Specifies a list of paths that are used to search for files that can be run. When running a executable file, assuming that the file cannot be found under the current path, look for each path in path until it is found. Or if you find the path in the paths can not be found, the error. Java's compile command (JAVAC), Run command (Java), and some tool commands (Javadoc, JDB, and so on) are in the Bin folder under its installation path. So we should add that path to the path variable.
CLASSPATH: also specifies a list of paths that are used to search for Java compilations or classes that need to be executed. In addition to being able to include paths in the CLASSPATH list, you can include. jar files. The Java lookup class treats the. jar file as a folder for lookups. In general, we need to include Jre/lib/rt.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, the delimiter is a semicolon (;), and under Linux, the delimiter is a colon (:).
Here's how the three environment variables are set under Windows and Linux, but before we do, we need to do a If. If the JDK installation path under Windows is c:/jdk/, the installation path under Linux is/usr/local/jdk/. Then, the installed JDK will contain at least the following, for example:
C:/JDK (/USR/LOCAL/JDK)
|--bin
|--Demo
|--include
|--JRE
| |--bin
| '--Lib
'--Lib
Under Windows settings
The SET command environment variable setting is used under Windows, in order to set these environment variables for each boot computer, it should be set in the Autoexec.bat file under the System Packing folder, for example:
Set JAVA_HOME=C:/JDK
Set Path=%java_home%/bin; C:/windows; C:/windows/command
Set Classpath=%java_home%/jre/lib/rt.jar;.
Some versions of Windows cannot replace the contents of environment variables with the% variable name%, so it is only good to write c:/jdk instead of%java_home%. In addition, C:/windows and C:/windows/command are self-actively adding paths to Windows, so they can be removed from the settings. Assuming that path is already set in Autoexec.bat, it is only necessary to add the%java_home%/bin to the same statement that set the path.
CLASSPATH can also be set or added to other paths, for example, if you want to put some of the classes you write in C:/java, you can add C:/java to CLASSPATH, set Classpath=%java_home%/jre/lib /rt.jar; C:/java, ....
Notice that a "current folder (.)" is included in the CLASSPATH. Once the folder is included, it is possible to go to a random folder to run a Java program that requires a class under that folder, even if the path is not included in CLASSPATH. The reason is very easy: although it is not clear to include the path in CLASSPATH, but the "." In CLASSPATH at this point represents the path, such as:
If there is an executable class Hellojava.class under the C:/java folder, then
C:/> set Classpath=c:/jdk/jre/lib/rt.jar;. Set the CLASSPATH environment variable, and note that there is finally a "."
c:/> CD Java//Go to C:/java folder
c:/java> java Hellojava//execute Hellojava
Hello, Java. Execution results
c:/java> _
ggmm looking for a job , please go to www.ggmmjob.com to cast a resume .....
Set under Linux
Under Linux, use the variable name = variable value to set the variable and export it as an environment variable using the Export command. In order for each login to set these variables on its own initiative, you need to set them in ~/.bash_profile or ~./BASHRC, 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 the PATH is the value of the replacement variable Java_home to the location where the $JAVA _home. As the above sentence is actually export path=/usr/local/jdk/bin: $PATH. The $PATH in this sentence is the same, except that the path here refers to the value of the path variable that was set, not the value of the path variable this time.
Notice that a "current folder (.)" is included in the CLASSPATH. Once the folder is included, it is possible to go to a random folder to run a Java program that requires a class under that folder, even if the path is not included in CLASSPATH. The reason is very easy: although it is not clear to include the path in the CLASSPATH, but the CLASSPATH in the "." At this point represents the path, such as
If there is an executable class Hellojava.class under the/home/fancy/java folder, then
[Email protected] fancy]$ export Classpath=/usr/local/jdk/jre/lib/rt.jar:. Set the CLASSPATH, and note the last "."
[[Email protected] fancy]$ CD ~/java//Go to/home/fancy/java
[[email protected] java]$ pwd//Show current folder
/home/fancy/java//Current folder is/home/fancy/java
[[Email protected] java]$ java Hellojava//execute Hellojava
Hello, Java//execution result
[Email protected] java]$ _
Analysis
Example analysis
Only the operating system is different, a slight difference.
Both examples refer to an "executable class", which refers to a class that includes the public static void main (string[] args) method, which is detailed in the next chapter, Hellojava. The CLASSPATH in the example do not include the folder where Hellojava.class resides (C:/java,/home/fancy/java), but the current folder (.) is included. So go to the folder that includes Hellojava.class and execute Java hellojava, looking in Java for CLASSPATH ". (current folder, C:/java,/home/fancy/java) "When Hellojava.class was found, execution succeeded.
ggmm looking for a job , please go to www.ggmmjob.com to cast a resume .....
Java environment variable Configuration