Tutorials to .com

Tutorials to .com » Jsp » Application » Java Path

Java Path

Print View , by: iSee ,Total views: 30 ,Word Count: 1267 ,Date: Tue, 25 Aug 2009 Time: 10:09 PM

*** Change *** iamfancy (border town mad)

Usually, we need to set three environment variables: JAVA_HOME, PATH and CLASSPATH.

JAVA_HOME: This environment variable is the directory where Java, a number of java version of the software and some java tools need to use the variable, set the PATH and CLASSPATH, when you can use the variable to facilitate the setting.

PATH: Specifies a path list to search for executable files. The implementation of an executable file, if the file can not be found in the current path, then the PATH in turn for each of the path, until you find. Or to find the path End PATH can not find, an error message. Java compilation command (javac), execute the command (java) and a number of tools for the command (javadoc, jdb, etc.) are installed under the path of the bin directory. Therefore, we should add the path to the PATH variable.

CLASSPATH: also specify a path list is used to search for Java to compile or run-time need to use the class. In addition to the list in the CLASSPATH can contain a path, but also can be included. Jar file. Java classes will find it. Jar file as a directory to find out. Usually, we need to JDK installation path of the jre \ lib \ rt.jar (Linux: jre / lib / rt.jar) included in the CLASSPATH.

PATH and CLASSPATH are specified path list, the list of all (that is, the various paths) between the use of separator-delimited. In Windows, the separator is a semicolon (;), while in Linux, the separator is a colon (:).

Below separately for each of three environment variables in Windows and Linux how to set up, but in the meantime, we need to be a hypothesis. Suppose JDK on Windows, the installation path is C: \ jdk \, under the Linux installation path is / usr / local / jdk /. Then, after installation of the JDK will at least include the following:

C: \ jdk (/ usr / local / jdk)
| - Bin
| - Demo
| - Include
| - Jre
| | - Bin
| `- Lib
`- Lib

***** In Windows, set up

Windows, use the set command to set environment variables, in order that every time you start your computer are set up these environment variables, it should be packing in the system directory of the autoexec.bat file set, such as:

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 can not use variable names%% environment variable to replace the contents, then go straight to write C: \ jdk instead of% JAVA_HOME% of. In addition, C: \ Windows and C: \ Windows \ Command is Windows will automatically join the path, so it can be removed from the set. If the autoexec.bat has been set up PATH, Nazhi need to% JAVA_HOME% \ bin added to the original set the PATH to which the statement on the list.

CLASSPATH may also need to set up or join the other according to the path, for example you want to write some of their classes on the C: \ java in, you can put C: \ java also added to the CLASSPATH and going, set CLASSPATH =% JAVA_HOME% \ jre \ lib \ rt.jar; C: \ java;..

Note that in the CLASSPATH contains a "current directory (.)"。 Contains the directory, you can go to any directory in the directory implementation needs to use a certain type of Java program, even if the path is not included in the CLASSPATH can also be. The reason is simple: Although there is no clear-cut to the path included in the CLASSPATH, but in the CLASSPATH "." At this point on behalf of the path, such as:

Suppose C: \ java directory to run under the class HelloJava.class, then the

C: \> set CLASSPATH = C: \ jdk \ jre \ lib \ rt.jar;. / / Set the CLASSPATH environment variable, pay attention to the last one "."
C: \> cd java / / go to C: \ java directory
C: \ java> java HelloJava / / run HelloJava
Hello, Java. / / Run Results
C: \ java> _

The cases analyzed in Section 1.3.3.

**** Under the settings in the Linux

Under Linux use "variable name = variable value" to set a variable, and use the export command to export the environment variable. In order to log on each of these variables are automatically set up, you need to ~ /. Bash_profile where, or ~. / Bashrc Lane set, such as the

export JAVA_HOME = / usr / local / jdk
export PATH = $ JAVA_HOME / bin: $ PATH
export CLASSPATH = $ JAVA_HOME / jre / lib / rt.jar:.

PATH is set when the $ JAVA_HOME is used to replace the value of the variable JAVA_HOME to the $ JAVA_HOME location. As sentence is actually the export PATH = / usr / local / jdk / bin: $ PATH. Sentence in the $ PATH is also the same effect, but the PATH here refers to the previous set PATH variable, rather than this set PATH variable.

Note that in the CLASSPATH contains a "current directory (.)"。 Contains the directory, you can go to any directory in the directory implementation needs to use a certain type of Java program, even if the path is not included in the CLASSPATH can also be. The reason is simple: Although there is no clear-cut to the path included in the CLASSPATH, but in the CLASSPATH "." At this point on behalf of the path, for example,

Assuming / home / fancy / java directory to run under the class HelloJava.class, then the

[fancy @ matrix fancy] $ export CLASSPATH = / usr / local / jdk / jre / lib / rt.jar:. / / set the CLASSPATH, note that the last "."
[fancy @ matrix fancy] $ cd ~ / java / / go to / home / fancy / java
[fancy @ matrix java] $ pwd / / display the current directory
/ home / fancy / java / / the current directory is / home / fancy / java
[fancy @ matrix java] $ java HelloJava / / run HelloJava
Hello, Java / / running results
[fancy @ matrix java] $ _

The cases analyzed in Section 1.3.3

***** Case Study

Section 1.3.1, and 1.3.2 section is actually used in the same example, but the operating system is different from slightly different.

Two examples have referred to a "run of category", it refers to contains the public static void main (String [] args) method of the class, which will be detailed in the next chapter HelloJava 1. Cases were not included in the CLASSPATH the directory HelloJava.class located (C: \ java, / home / fancy / java), but contain the current directory (.). So go to the directory that contains HelloJava.class continue the implementation of java HelloJava, in Java to find in the CLASSPATH. "(The current directory, C: \ java, / home / fancy / java)" when found HelloJava.class, running a successful .


Java Application / Other Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.