The Jdk+tomcat+maven__linux of Linux environment variables

Source: Internet
Author: User

This is a screenshot of the environment variables that have been configured to complete

Operating Environment: Linux

one. Java Configuration Environment Variables

Why do you want to set environment variables? The reason is simple: First, the Java file is compiled with the Javac command to generate the. class file, which, in the Java JDK, must know where it is stored in order to execute it. Second, the Java file executes the compiled. class file, so you must know where the compiled. class file is placed. (The Java command was executed, and he was with Javac in the JDK). Environment variables must be configured based on the above two requirements. The following detailed description: Java_home, PATH, CLASSPATH. (First outline and then detailed)

1. Java_home: It points to the installation directory of the JDK, Eclipse/netbeans/tomcat software that searches java_home variables to find and use the installed JDK.

2. Path: The role is to specify the command search path, which, when executed under the shell, looks for the appropriate command program to be found in the path specified by the PATH variable. We need to add the bin directory in the JDK installation directory to the existing path variable, the bin directory contains the frequently used executable files such as Javac/java/javadoc, and so on, after setting the path variable, you can execute the Javac/java tools in any directory.

3. CLASSPATH: The role is to specify the class search path, to use the class that has been written, if you can find them, the JVM (Java Virtual machine) is through the classpth to find the class. We need to set the Dt.jar and Tools.jar in the Lib subdirectory under the JDK installation directory to classpath, of course, the current directory "." must also be added to the variable.

Note 1: The system variable path is for the entire operating system, CLASSPATH is for specialized Java

Note 2: The so-called JVM is like to activate another operating system on the operating system, and for the JVM classpath is like a path to the operating system, so it is necessary to set the CLASSPATH to run the program with the JVM.

Note 3:classpath inside should add Rt.jar, Dt.jar, Tool.jar it.
A: Rt.jar is not required, the JDK will automatically load. Tools.jar and Dt.jar are class library paths. If you don't use the things in swing, you can add Dt.jar. Tools.jar inside is the most basic tool class, such as Javac, not add is unable to do development.

Let's look at the Java environment variables set up in/etc/profile on the server


A Use colon ":" Under Linux to separate paths
B. $path/$JAVA _home/$CATALINA in export PATH _home is used to refer to the value of the original environment variable
C. Classpath in the current directory "." Can't Lose

two. Whether Tomcat configures environment variables (as needed, individuals feel that they are not configured to do so)

(for example,/data/workspace_dubbo/tools/tomcat-rcservice on 20 servers to discuss how to start Tomcat)

01. Do not configure environment variables

Switch to the/data/workspace_dubbo/tools/tomcatdubbo-tcservice/bin directory to execute the./catalina.sh Run command (also available under other directories). Indicate the position of the catalina.sh)

02. Configure Environment variables (configured in/etc/profile)


After you configure the Tomcat environment variable in/etc/profile, you can execute the catalina.shrun command in any directory without pointing out the location of the catalina.sh because it is already configured in the environment variable. Personally feel that configuring an environment variable is more appropriate for a TOMCA situation on the current server. (if there are multiple tomcat, configure one, others do not configure)

Q1: Why the command entered in 01 cases is./catalina.sh run,02 the command to enter is catalina.sh run? (represents the current directory, ... Represents a previous level of directory)

A: 01 is not set environment variables, start Tomcat must tell the system catalina.sh command position, otherwise the system can not find. Switch to the Tomcatdubbo-tcservice/bin directory to start Tomcat, "./catalina.sh run"./that is to tell the system catalina.sh location. You can also start Tomcat in any directory, and also tell the system catalina.sh location


02 is to set environment variables, in any directory can run catalina.sh

The role of q2:/

Answer:/For the path separator,
/This symbol represents the root directory at the front. For example,/boot, which represents the boot directory under the root directory, is followed by the separator between the directories

Note 1:export command

Feature Description: Sets or displays environment variables.

Syntax: Export [-fnp][variable name]=[variable set value]

Supplemental Note: When executing a program in a shell, the shell provides a set of environment variables. Export can add, modify, or delete environment variables for use by subsequent programs. The validity of export only extends to the login operation.

Parameters:

-F represents the function name in the variable name.

-n Deletes the specified variable. Variables are not actually deleted, but are not exported to the execution environment of subsequent directives.

-p lists all the environment variables that the shell assigns to the program.

The export setting is valid only for the current bash logon session. The export command can be placed inside the/etc/profile, the login will be executed in the file inside the command, for all users are valid.

Q3: Why is the Tomcat environment variable set in/etc/profile, and after saving in any directory catalina.sh run will prompt

A: Modifying the environment variable in/etc/profile will not take effect immediately: when you log on to Linux, it will load/etc/profile, and you will not be able to modify this file until you log on. For an environment variable to take effect, either log back in or source to make it effective immediately.

Q4:tomcat_home and Catalina_home

A: According to the environment variables previously set, Java_home represents the installation directory of the JDK, then you should use Tomcat_home to represent the Tomcat installation directory, but why use Catalina_home? In fact, before Tomcat 4, it was tomcat_home to represent the Tomcat installation directory, and after Tomcat 4, a new servlet container Catalina was used, so the name of the environment variable was changed to Catalina_home.

Q5: Environment variables are case-sensitive.

A: Linux and windows are case-insensitive and have been validated under Linux

Note 2:source command

Modified the/etc/profile file, want it to take effect immediately, without having to log in again, then think of the source command, such as: Source/etc/profile
SOURCE command:
The source command, also known as the Point command, is a dot symbol (.) and is the internal command for bash.
Function: Enables the shell to read the specified shell program files and execute all statements in the file sequentially
The source command is typically used to rerun an initialization file that has just been modified to take effect immediately, without having to log off and log on again.
Usage: source filename or. FileName
SOURCE filename and SH filename and./filename the difference between executing scripts is there.
1. When the shell script has executable permissions, there is no difference between executing the script with SH filename and./filename./filename is because the current directory is not in path, all "." is used to represent the current directory (same as./catalina.sh run, if you do not set the environment variable, be sure to tell the system its location).
2.sh filename to re-establish a child shell, in the child shell execute the statement inside the script, the child shell inherits the parent shell environment variables, but the child shell new, changed variables will not be brought back to the parent shell, unless the use of export.
3.source FileName: This command actually simply reads the statements in the script and executes them sequentially in the current shell, without creating a new child shell. All new, variable-change statements in the script are saved in the current shell.


three. MAVEN Configuration Environment Variables

Take the 20 server/data/workspace_dubbo/tools/maven as an example, if you do not configure the environment variable, you must take the path of the command every time you execute the MAVEN command


For ease of operation, configure MAVEN's environment variables in/etc/profile

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.