Windows environment variable path and other detailed tutorials

Source: Internet
Author: User
Tags parent directory tomcat

An environment variable is an object with a specific name in the operating system that contains the information that one or more applications will use. For example, the PATH environment variable in Windows and DOS operating systems, when the system is required to run a program without telling it the full path of the program, the system should also go to the path specified in paths, in addition to finding the program under the current directory. Users to better run the process by setting the environment variables.

First, the basic principle

First look at the PATH environment variable.

Java Beginners, you must learn to configure the path environment variables, otherwise can not compile, run Java programs. So why do you want to configure the PATH environment variable? What does the PATH environment variable do? Let's start with a common problem.

When we have installed Java, if the PATH environment variable is not configured correctly, when you run the command java-version (show Java Version) command at the Command Line window (start-> run-> input cmd, enter) The following error message appears:

This error message means that you asked to run the “java” command I do not know what is a thing. So what is this “java” order sacred? In the JDK installation directory (mine is d:javajdk1.6.0_24), there is a bin directory. Open this directory, you will find a large number of executable files (suffix named exe file.) Windows default hidden file suffix name. To display the suffix name, click “ Tools ” Menu-> Folder Options in the top menu bar of the current window-> view-> Advanced Settings-> purge “ Hide extensions for known file types ” front hook-> OK). One of the executable files is java.exe. Now switch the current directory to this bin directory under the Command Line window. Implemented by the following command:



Under this directory, run the dir command to display all the files and directories in the current directory. From the display result, we can see the “java.exe” file clearly. As shown in the following illustration:



In fact, we execute the “java” command to run “java.exe” the executable (we run other commands that are essentially executing a program file). Let's try the “java-version” command now. Type java-version under the Command Line window, and enter the results as shown in the following figure:



It seems that the execution has been successful. The command results show that the current Java version is “1.6.0_24”. Execute Java-? To view help information for this command. You can see that it has many options, and-version is just one of them. Alternatively, write down the complete (absolute) path of these executables (for example, D:javajdk1.6.0_24binjava-version), which can be executed in any directory. Readers can try it on their own.

Like Java commands, the Javac command can now be executed in the bin directory, but it can only write its full path to other directories. In the process of learning Java, we often need to use the Javac and Java two commands to compile, run our Java program. Do we have to switch to the bin directory every time we run these two commands, or write a long list of absolute paths? Is there a way that we can run these commands freely in any directory?

The solution lies in the PATH environment variable.

Path is the meaning of paths, and the value stored in the PATH environment variable is a series of paths. Separate paths, separated by semicolons (;) in English. When the system executes a user command, if the user does not give an absolute path, first look for the corresponding executable file, batch file (another executable file) in the current directory. If you can't find them, then look for the appropriate executable program files in the path saved in the paths. The system is whichever is first found; if all paths saved by path are not found, an error message similar to Tuyi is displayed.

With this in hand, we add the full path of the bin directory to the path. Under the Command Line window, you can use the SET command to accomplish tasks of this class. Running set directly shows the value of all current environment variables for the system, running set/?, and displays help on this command. The format for setting the environment variable value using the SET command is: Set environment variable NAME = environment variable value. We can use the command set Path=d:javajdk1.6.0_24bin to add the directory of Java and other program files to the PATH environment variable (Windows environment variable names are case-insensitive, unlike Unix). But that would make the path's value only “d:javajdk1.6.0_24bin&rdquo, and it would have been overridden to preset values for other programs to use. Therefore, we should append the value “D:Javajdk1.6.0_24bin” to the path. To do this, we can use the following command:

Set path=%path%;D: Javajdk1.6.0_24bin

Place the path between the two percent sign, which means that the value of the path is taken out. The semicolon that follows separates the different path values, and then the values we want to add. Note that you use this command in the English input method state. Now we go to any directory to execute the java-version command to try. The results are shown in the following illustration:



Visible run complete success.

However, the environment variable set by using the SET command is only valid for the current command-line window. Once you close this window and run another command line window again, the PATH environment variable is the same as the original value. Therefore, we must modify the PATH environment variable under Windows. The steps are as follows:

Right-click the desktop “ My Computer ” icon-> Properties-> Advanced-> Environment variables, the dialog box that sets the environment variable is opened. The above section is set for a user. Windows is designed to use a single machine for multiple users, one account per person. Variables set for an account are valid only for that user. The following section sets the system variables to be valid for each user in the system. Now the general computer has only one user, that is, the administrator. So you just need to set up this account. Locate the PATH environment variable, point “ edit ”. Enter the semicolon for the English input method after the existing value in the “ variable value ” box, and then add the value you want to add (here is D:javajdk1.6.0_24bin). All the way OK, ok!

Now open a Command line window and enter the Echo%path% command to view the value of the path (or use the path command directly). Now we can see that the bin directory has been added to the path and then run the java-version command in any directory to succeed. As shown in the following illustration:



In fact, it's the principle that we execute other orders. For example, when you display the value of path, you will find that the first value is c:windowssystem32. Open this directory under Windows and you will see a lot of executable files whose names are the same as the names of the commands we use. That is, we execute these commands, and the system actually finds the corresponding executable file based on the value of path, and then runs the results of those files. such as the Attrib.exe file, which corresponds to the attrib command, which is the command to display/set the file properties, as shown in the following illustration:



Now we're going to clear the value of the path by using the command set path= (there's nothing on the right side of the equals sign, or something to write), and then run the attrib command. As shown in the following illustration:



You can see that the exact same command is now out of order and the error has been made.

The following is the command set Path=c:windowssystem32 (Windows is not case-sensitive, so windows and Windows are correct), add the path where the Attrib.exe file is located, and then try to run it. As shown in the following illustration:



It is clear that it has been able to run correctly now. Another common example is the Format.com (. com file is another executable file), but this command is used to format the experiment, please be careful not to format a disk because of a mistake. Also, according to the above description, when the PATH environment variable is not configured correctly, write out the absolute path (full path) of these files and execute correctly. The reader can experiment on his own (in this statement, due to the prior reminders, so all due to incorrect operation of the data loss, not responsible!) )。

Ii. internal commands, external commands and batch files


We now start a command line window that clears all the path values as described above, and then runs the commands such as Dir, CD, and so on. To our surprise, they are still able to execute correctly. And what is the reason?

Let's take a look at the information that just reported the error, they all mentioned the concept of “ internal command ” and “ external command ”. So what are internal commands and external commands?

Internal commands and external commands are the concepts of DOS (disk operating system, Microsoft's early command line operating system), and Baidu Encyclopedia explains that internal commands are loaded and resident with each boot command_com, and the external command is a separate executable file. Roughly speaking, the so-called internal command is the most core, the most used command. In order to improve the response speed, when the system starts, the commands are loaded into memory so that they can be executed quickly and directly, and the external commands are not preloaded into memory because they are used relatively infrequently, and then to the hard disk (c:windowssystem32) when the user is in use, to find the corresponding executable file, Then load into memory execution. Like Dir, CD, etc. are internal commands, and such as attrib, format, etc. are external commands. Although the era of DOS has long been history, some operations must be done in command-line mode, especially for professionals. As a result, the Windows product retains the command line mode tool.

Another concept is the batch file (the suffix named. bat, the English word batch from the batch), which is another executable file. Simply put, the batch file contains many DOS commands. Execute these commands in a single article when the file is executed. Not necessarily sequential execution, like a general-purpose programming language, it has its own process control. Batch file creation is simple: Create a text file with any text editor (such as Windows Notepad) and change the suffix name to. bat. To create a good batch file, you can also open it with a text editor to view its “ source ”.

Iii. settings for Catalina_home environment variables (for TOMCAT6/7)


Tomcat is a free and open source servlet/jsp container, well received by the vast number of Java beginners love. This requires setting the CATALINA_HOME environment variable, which is the Tomcat installation directory (mine is D:TOMCAT7), or the following error message appears:



This means that the CATALINA_HOME environment variable is not set correctly, and this variable is necessary to run Tomcat. And when you disregard this information, you can also succeed when you switch the current directory to the bin directory under the Tomcat installation directory in the Command Line window, and then execute the batch file Startup.bat to start Tomcat. Don't you need to catalina_home the environment variable now?

In fact, in Startup.bat, the first thing to determine is whether catalina_home is empty. If empty, the current directory is set to the Catalina_home value. Then find out if there is a bin directory under the directory indicated by Catalina_home, and whether there is a batch file called Catalina.bat in this bin directory (this file is responsible for starting Tomcat). If not, set the parent directory of the current directory to the Catalina_home value, and repeat the lookup above. If you still fail, report the error shown in Figure 10. Therefore, when you run the Startup.bat file in the bin directory under the Tomcat installation directory, it automatically sets the value of the catalina_home correctly in the second way as described above. Because the Catalina.bat file is in the bin directory under the Tomcat installation directory.

Although it works correctly in this case, it is recommended that you set the CATALINA_HOME environment variable correctly. Unlike path, the path system itself is created by, and Catalina_home needs you “ new ” “ environment variable ” window point “ New ” can be.

To be able to run a batch file in the Bin directory under the Tomcat installation directory in any directory, such as Startup.bat, add this directory to the PATH environment variable (mine is D:tomcat7bin). To increase flexibility, you can add%catalina_home%bin to the end of the PATH environment variable (don't forget to separate it from the previous value with a semicolon in English). Place the catalina_home between two percent signs that refer to the value of this environment variable. This way, when you change the Tomcat installation directory, you only need to modify the value of the Catalina_home, and you do not need to modify the path value, because it automatically calculates the new correct value.

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.