Windows下 如何配置TomCat

TomCat是一個標準的容器,爲Servlet等組件提供了良好的運行環境;

TomCat是Apache旗下的產品,開源免費;目前最新版本是TomCat 8.0.15;

下載TomCat可以去下面的連接地址:

Apache的TomCat官網

官網的左邊有Download的區域,可以選擇自己需要的版本;


點擊進去,在Core(內核/核心)模塊,可以下載到TomCat版本;一般選擇zip下載

下載完成後,就解壓就可以用了,因爲TomCat也是使用Java語言編寫,所以只要系統裏面有JRE(java運行環境),配置好環境就可以運行了;

--------------------------------------------------------------------------------------

如何配置TomCat系統環境(Windows)呢?


首先,右擊計算機--屬性


然後點擊,高級系統設置


在高級選項卡中,選擇“環境變量”


這時纔是真正開始配置的關鍵;


=======================================================================

首先注意:

對於部分用戶,只需要配置“系統變量”就行了,

但是,對於大部分用戶,建議同時配置“系統變量“和”用戶變量“

也就是,配置兩遍;如何在“系統變量“中配置,也要在”用戶變量“同樣的配置;


具體步驟:


1.配置CATALINA_HOME環境變量


變量名是固定的,變量值是指TomCat的解壓路徑(根目錄),

注意,變量名建議大寫(我不知道小寫,會不會導致不正常)

其次,變量值後面不能加“;”或者“\”,這都會導致配置失敗;

TomCat的官方推薦,我們需要再配一個環境變量,名字叫做:CATALINA_BASE

變量值也是TomCat的解壓路徑(根目錄)


2.配置path

在環境變量Path中,新增加“%CATALINA_HOME%\lib;%CATALINA_HOME%\bin;"


這是方便調用類庫的;


3.配置JRE_HOME 或 JAVA_HOME

JRE_HOME就是Java安裝目錄下的jre目錄

而JAVA_HOME就是java安裝目錄下的jdk目錄

變量值後面不能加“;”或者“\”,這都會導致配置失敗;


配置如下:




這樣配置就基本成功了,現在只需要驗證一下:

開始--運行--輸入cmd,打開


打開cmd,輸入startup.bat


如果配置成功的話,就會出現下面的提示,並且跳出窗口


打開瀏覽器,輸入:http://localhost:8080, 看tomcat是否正常啓動
關閉tomcat:

進入命令行cmd,輸入shutdown.bat

==================================================================

下面是TomCat的官方配置指導:

(3.1) Set CATALINA_HOME (required) and CATALINA_BASE (optional)

The CATALINA_HOME environment variable should be set to the location of the root directory of the "binary" distribution of Tomcat.

An example was given in (2.2) above.

The Tomcat startup scripts have some logic to set this variable automatically if it is absent, based on the location of the startup script in *nix and on the current directory in Windows. That logic might not work in all circumstances, so setting the variable explicitly is recommended.

The CATALINA_BASE environment variable specifies location of the root directory of the "active configuration" of Tomcat. It is optional. It defaults to be equal to CATALINA_HOME.

Using distinct values for the CATALINA_HOME and CATALINA_BASE variables is recommended to simplify further upgrades and maintenance. It is documented in the "Multiple Tomcat Instances" section below.



(3.2) Set JRE_HOME or JAVA_HOME (required)

These variables are used to specify location of a Java Runtime Environment or of a Java Development Kit that is used to start Tomcat.

The JRE_HOME variable is used to specify location of a JRE. The JAVA_HOME variable is used to specify location of a JDK.

Using JAVA_HOME provides access to certain additional startup options that are not allowed when JRE_HOME is used.

If both JRE_HOME and JAVA_HOME are specified, JRE_HOME is used.

The recommended place to specify these variables is a "setenv" script. See below.



(3.3) Other variables (optional)

Other environment variables exist, besides the four described above. See the comments at the top of catalina.bat or catalina.sh scripts for the list and a description of each of them.

One frequently used variable is CATALINA_OPTS. It allows specification of additional options for the java command that starts Tomcat.

See the Java documentation for the options that affect the Java Runtime Environment.

See the "System Properties" page in the Tomcat Configuration Reference for the system properties that are specific to Tomcat.

A similar variable is JAVA_OPTS. It is used less frequently. It allows specification of options that are used both to start and to stop Tomcat as well as for other commands.

Note: Do not use JAVA_OPTS to specify memory limits. You do not need much memory for a small process that is used to stop Tomcat. Those settings belong to CATALINA_OPTS.

Another frequently used variable is CATALINA_PID (on *nix only). It specifies the location of the file where process id of the forked Tomcat java process will be written. This setting is optional. It will enable the following features:

 *  better protection against duplicate start attempts and
 *  allows forceful termination of Tomcat process when it does not react to the standard shutdown command.

(3.4) Using the "setenv" script (optional, recommended)

Apart from CATALINA_HOME and CATALINA_BASE, all environment variables can be specified in the "setenv" script. The script is placed either into CATALINA_BASE/bin or into CATALINA_HOME/bin directory and is named setenv.bat (on Windows) or setenv.sh (on *nix). The file has to be readable.

By default the setenv script file is absent. If the script file is present both in CATALINA_BASE and in CATALINA_HOME, the one in CATALINA_BASE is preferred.

For example, to configure the JRE_HOME and CATALINA_PID variables you can create the following script file:

On Windows, %CATALINA_BASE%\bin\setenv.bat:

  set "JRE_HOME=%ProgramFiles%\Java\jre6"
  exit /b 0

On *nix, $CATALINA_BASE/bin/setenv.sh:

  JRE_HOME=/usr/java/latest
  CATALINA_PID="$CATALINA_BASE/tomcat.pid"

The CATALINA_HOME and CATALINA_BASE variables cannot be configured in the setenv script, because they are used to locate that file.

All the environment variables described here and the "setenv" script are used only if you use the standard scripts to launch Tomcat. For example, if you have installed Tomcat as a service on Windows, the service wrapper launches Java directly and does not use the script files.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章