1. Background description
Sometimes we customize some environment variables in the or file, such as specifying additional JDK paths or setting JVM parameters.
In fact, it is not standard practice to customize environment variables directly in the or file.
That's because inWhen performing a (minor) upgrade of Tomcat, a new version of the or file will overwrite the old version of the file, thus invalidating the original custom environment variables.
In this regard, Tomcat officials have included a note in the (or ) file (see below) suggesting the use of the (or ) configuration file (which needs to be created additionally) to save custom environment variables.
2、Specify the JDK path
2.1, Windows
2.1.1 Before specifying the JDK path
As shown above, before you configure Tomcat's custom environment variables, Tomcat defaults to using the JDK paths configured by the (Windows) system environment variables.
2.1.2 Specify JDK path command
As shown in the above figure, first create a file in the bin directory of Tomcat, edit the command to specify the path to the JDK, and then change the txt suffix to bat.
set JAVA_HOME=Custom JDK path
2.1.3 After specifying the JDK path
As shown above, the specified JDK path was successfully used through the file.
2.2, Linux system
Note: On Linux systems, Tomcat uses the JRE path, so you need to specify JRE_HOME instead of JAVA_HOME.
2.2.1 Before specifying the JRE path
As shown above, Tomcat defaults to using the JDK path configured by the (Linux) system environment variable before configuring Tomcat's custom environment variables.
2.2.2 Specify JRE path command
As shown in the figure above, first create a file in the bin directory of Tomcat, edit the command that specifies the path to the JRE, and then add execution permissions (chmod +x) to the script file.
JRE_HOME="Customize jre path"
2.2.3 After specifying the JRE path
As shown above, the specified JRE path was successfully used through the file.
3. Setting JVM parameters
3.1. Windows
3.1.1 Setting JVM Parameters Command
-Xms: Set the memory when the JVM is initialized;
-Xmx: Sets the maximum memory available to the JVM;
These two values are generally set to the same size to avoid the JVM reallocating memory after each garbage collection is complete.
set JAVA_OPTS=-Xms custom size -Xmx custom size
3.1.2. After setting the JVM parameters
As shown in the above figure, the set JVM parameters were successfully used through the file.
3.2. Linux systems
3.2.1 Setting JVM Parameters Command
-Xms: Set the memory when the JVM is initialized;
-Xmx: Sets the maximum memory available to the JVM;
These two values are generally set to the same size to avoid the JVM reallocating memory after each garbage collection is complete.
JAVA_OPTS="-Xms custom size -Xmx custom size"
3.2.2. After setting the JVM parameters
As shown in the above figure, the set JVM parameters were successfully used through the file.
this paper references
[1] [zno2] [] [Blogland] [2016-10-17]
[2] [song854601134] [tomcat in the management of environment variables of] [CSDN] [2024-05-31
[3] [and walk and think] [Tomcat by specifying jdk and jre (relative paths)] [Blog Park] [2023-06-28
[4] [yuer!] [How to change the specified jdk path of tomcat under linux] [Blog Park] [2020-04-02].