Why should Java configure environment variables, how to configure

Source: Internet
Author: User

Summarize some of your own and add some more:
To configure environment variables after installing the JDK, there are three main:
1 Java_home, the installation directory for the JDK, such as: F:\JAVA\jdk1.6.0_04
2 CLASSPATH where to find the. class file that you need to execute, such as:.; %java_home%\lib;
The front is a point [.] Add a semicolon [;] End with a semicolon [;]
Why add some [.] When compiling a Java file, such as Javac Xxx.java, the Xxx.class file is generated in the current directory.
Then with the Java XXX execution, the system will be in the current directory to find Xxx.class files, so to add, the representative is in the current directory to find a class file to execute.
3 path->javac.exe of the execution program, such as:%java_home%\bin;
Start menu, run->cmd, enter regedit in the console, return to see the registration form! The process is that when you enter Regedit, the system will go to the system environment variable to find the path of the program's executable file. Open the settings of the system environment variables, you will see the system variable windir value of%systemroot% (in fact, C:\WINDOWS if the system is installed in the C disk), we re-open C:\WINDOWS, you can find a program called Regedit.exe!
Set the purpose of the system variable: In order to make the system can find the running path of the program!
When setting the environment variable path, why Choose C:\Java\jdk1.6.0\bin (the JDK's installation directory)? Open the directory, and found that there are all the executable files, including our most familiar javac.exe,java.exe and so on. Yes, the reason to choose Bin is because when we compile the program, in the console input Javac Hello.java is, the system to go to the system environment variable Javac.exe to find the execution program path.

The following parameters should be introduced first:
Current directory:
The directory currently in use is the current directory. For example, when you open Notepad, and in the running state, the current directory is c:/windows; If you open a command-line window with the cmd command, the current directory is c:\windows\system32; If you are using the Java directive, the current directory is the path to the bin directory under Java because Java.exe is in the bin.
When the Java Development Configuration environment variable, the system default (we do not make any settings to Classpath) path is also the current directory.
Java_home:
It refers to the JDK's installation directory, like D:\j2sdk1.4.2_16.
You can create a new java_home variable with a value of D:\j2sdk1.4.2_16.
Why set it up, don't set it? Not set is also can drop, but it is best to set up a bit.
Now, let's just take it as a variable substitution java_home = D:\j2sdk1.4.2_16, which is to avoid writing, it also has the advantage that when we need to change a JDK, only the value of Java_home can be changed. You'll understand when you see Tomcat's startup analysis in the back.
Use%java_home% to represent D:\j2sdk1.4.2_16 when referencing it in an environment variable.

Path:
The system variable path tells the operating system executable file (*.exe, *.bat, etc.) where the path, when the OS (operating system) found a *.exe, windows by default from the current directory to find this command, if not found, the OS will go to path set to find that command, And then execute.
The system default system variable is: Path =%SystemRoot%; %SystemRoot%\System32; %systemroot%\system32\wbem
That is, in the above 3 directories (multiple variables separated by semicolons) in the *.exe file, can be executed anywhere (commands that can be executed directly in the Run window, such as CMD, Notepad, etc., basically in the above 3 directories), so they can run directly.
What does the above%systemroot% mean? %systemroot% is the default installation path when installing the operating system
If your WINDOWS XP is installed in C:/windows
Then your%systemroot% path is c:/windows.
%systemroot% is just a symbol that represents your system installation directory
The following are the common system default installation paths:
98----C:/windows
2000--c:/winnt
2003--c:/windows
XP----C:/windows
When it comes to JAVA development, the OS often needs to use Java.exe, Javac.exe, etc. (if the JDK is installed in D:\j2sdk1.4.2_16) so D:\j2sdk1.4.2_16\bin (%java_home%\ BIN) into the path of the system.
Note: If you join the location is not at the end, then you need to add a semicolon after the bin in the English state:%java_home%\bin; Use semicolons to separate multiple variables, and if not, you add one.
Clear:%java_home%\jre\bin This path is not required to join path. Reference: http://java.sun.com/javase/6/docs/technotes/tools/windows/jdkfiles.html
CLASSPATH:
Classpath is specifically for Java, which is equivalent to Windows Path;path for the entire windows.
Classpath tells the Java Virtual Machine (JVM) where to put the *.class files to be used or executed.
The so-called JVM is like activating another OS on the Microsoft OS, classpath to the JVM as if it were a path to the Microsoft OS, so you need to set CLASSPATH to run the program with the JVM, However, like Windows, the JVM also has a default path to find the class file, for us, just beginning to learn Java, the default is enough for us, that is the current path, so do not set Classpath can also.
There is no relationship between classpath casing in Windows, and the other environment variable names.
Reference:
Http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html
If you use other resource files in classpath, it means you are already familiar with classpath, and you can set it yourself at your own discretion.
When we do not set CLASSPATH, the system default classpath is the current directory, if you personally want to set classpath, then be sure to add "." In the Classpath, the point in the English state indicates the current directory.
As for the classpath to join other paths (including file directory, the root of the package, etc.), this depends on the development needs, generally we beginners are not available.
Path of the setting is no doubt, but Classpath have doubts, in the end should add Rt.jar, Dt.jar, Tool.jar?
It is certain that the rt.jar is not needed and the JDK will be loaded automatically. You can use the Java-verbose command to view it.
We can look at what the Tools.jar and Dt.jar under%java_home%\lib are:
Http://java.sun.com/javase/6/docs/technotes/tools/windows/jdkfiles.html or
Http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/jdkfiles.html
Does that tools.jar,dt.jar need to add to classpath in the end? I've looked at some of the data, and in Sun JDK 1.2 and later, there's a set of APIs that can compile and execute Java code at the moment the program runs. These APIs are included in the Tools.jar class library. This feature allows Java programs to dynamically compile and execute small blocks of code at run time, which in some cases makes the architecture of Java applications more flexible and open. There was an example that I didn't read too well, so I didn't post it.
If you do not yet understand what is dynamic compilation or whether you need to "dynamically compile Java programs", it is not necessary, the system's own default settings, you are also the default good ^_^
As for the Dt.jar package, do not import it after jdk1.4.0, the runtime will be automatically imported-this is my collection of n data after the choice of a more secure and reassuring answer
Catalina_home:
Long story short, tomcat boot is not analyzed, tell you how to set it up, before Tomcat 4, using Tomcat_home to indicate the installation directory of Tomcat, the middle also used Tomcat_base, after Tomcat 4, The new servlet container Catalina is used, so the name of the environment variable is changed to Catalina_home, so the setting does not have to set the 3 variables, it is enough to catalina_home. If you install the decompression version can also not set catalina_home, directly double-click on the bin inside the Startup.bat can be, close when there is shutdown.bat.
In summary: (in WinXP) set the environment variable as the-D:\J2SDK1.4.2_16,TOMCAT installation directory for the JDK installation directory-d:\apachetomcat\apache-tomcat-6.0.14 The following: You can also refer to HTTP/ Java.sun.com/javase/6/docs/technotes/tools/windows/jdkfiles.html themselves decide what needs to be set.
Java_home = D:\j2sdk1.4.2_16
The PATH environment variable is added to the front (if the system was not originally created)%java_home

Why should Java configure environment variables, how to configure

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.