Tomcat setup in windows(simple version)
2016-09-19 09:23
351 查看
1. download tomcat server :
Goto http://tomcat.apache.org ⇒ Downloads ⇒ Tomcat 8.0 ⇒ "
Create your project directory, say "
For ease of use, we shall shorten and rename this directory to "
[b]Take note of Your Tomcat Installed Directory[/b]. Hereafter, I shall refer to the Tomcat installed directory as
2.Tomcat's Directories
Take a quick look at the Tomcat installed directory. It contains the following sub-directories:
bin: contains the binaries; and startup script (
conf: contains the system-wide configuration files, such as
lib: contains the Tomcat's system-wide JAR files, accessible by all webapps. You could also place external JAR file (such as MySQL JDBC Driver) here.
logs: contains Tomcat's log files. You may need to check for error messages here.
webapps: contains the webapps to be deployed. You can also place the WAR (Webapp Archive) file for deployment here.
work: Tomcat's working directory used by JSP, for JSP-to-Servlet conversion.
temp: Temporary files.
First, find your JDK installed directory. The default is "
To set the environment variable
⇒ In "Variable Value", enter your JDK installed directory as noted in Step 1.
To verify, RE-START a CMD shell (restart needed to refresh the environment) and issue:
Make a BACKUP of the configuration files before you proceed.
(a) "conf\server.xml" -
[b]Set the TCP Port Number[/b]
Use a programming text editor (e.g., NotePad++, TextPad for Windows; or gEdit, jEdit for Mac OS X) to open the configuration file "
The default TCP port number configured in Tomcat is 8080, you may choose any number between 1024 and 65535, which is not used by an existing application. We shall choose 9999 in this article. (For production server, you should use port 80, which is pre-assigned
to HTTP server as the default port number.)
Locate the following lines (around Line 69) that define the HTTP connector, and change
(b) "conf\web.xml" -
[b]Enabling Directory Listing[/b]
Again, use a programming text editor to open the configuration file "
We shall enable directory listing by changing "
Locate the following lines (around Line 103) that define the "default" servlet; and change the "listings" from "
(c) "conf\context.xml" -
[b]Enabling Automatic Reload[/b]
We shall add the attribute
Locate the
(d) (Optional) "conf\tomcat-users.xml"
Enable the Tomcat's manager by adding the highlighted lines, inside the
This enables the manager GUI app for managing Tomcat server.
(a) Start Server
For Windows
Launch a CMD shell. Set the current directory to "
(Skip Unless ...) Cannot Start Tomcat: Read "How to Debug".
(b) Start a Client to Access the Server
Start a browser (as HTTP client). Issue URL "
![](https://www.ntu.edu.sg/home/ehchua/programming/howto/images/TomcatHomePage.png)
Try issuing URL
(Optional) Try issuing URL
(c) Shutdown Server
For Windows
You can shutdown the tomcat server by either:
Press Ctrl-C on the Tomcat console; OR
Run "
WARNING: You MUST properly shutdown the Tomcat. DO NOT kill the cat by pushing the window's "CLOSE" button.
Goto http://tomcat.apache.org ⇒ Downloads ⇒ Tomcat 8.0 ⇒ "
8.0.{xx}" (where
{xx}is the latest upgrade number) ⇒ Binary Distributions ⇒ Core ⇒ "ZIP" package (e.g., "
apache-tomcat-8.0.{xx}.zip", about 8 MB).
Create your project directory, say "
d:\myProject" or "
c:\myProject". UNZIP the downloaded file into your project directory. Tomcat will be unzipped into directory "
d:\myProject\apache-tomcat-8.0.{xx}".
For ease of use, we shall shorten and rename this directory to "
d:\myProject\tomcat8".
[b]Take note of Your Tomcat Installed Directory[/b]. Hereafter, I shall refer to the Tomcat installed directory as
<TOMCAT_HOME>.
2.Tomcat's Directories
Take a quick look at the Tomcat installed directory. It contains the following sub-directories:
bin: contains the binaries; and startup script (
startup.batfor Windows and
startup.shfor Unixes and Mac OS X), shutdown script (
shutdown.batfor Windows and
shutdown.shfor Unix and Mac OS X), and other binaries and scripts.
conf: contains the system-wide configuration files, such as
server.xml,
web.xml,
context.xml, and
tomcat-users.xml.
lib: contains the Tomcat's system-wide JAR files, accessible by all webapps. You could also place external JAR file (such as MySQL JDBC Driver) here.
logs: contains Tomcat's log files. You may need to check for error messages here.
webapps: contains the webapps to be deployed. You can also place the WAR (Webapp Archive) file for deployment here.
work: Tomcat's working directory used by JSP, for JSP-to-Servlet conversion.
temp: Temporary files.
3. Create an Environment Variable JAVA_HOME
You need to create an environment variable called "JAVA_HOME" and set it to your JDK installed directory.
First, find your JDK installed directory. The default is "
c:\Program Files\Java\jdk1.8.0_{xx}", where
{xx}is the upgrade number. Take note of your JDK installed directory.
To set the environment variable
JAVA_HOMEin Windows 7/8/10: Start "Control Panel" ⇒ System ⇒ Advanced system settings ⇒ Switch to "Advanced" tab ⇒ Environment Variables ⇒ System Variables ⇒ "New" ⇒ In "Variable Name", enter "
JAVA_HOME"
⇒ In "Variable Value", enter your JDK installed directory as noted in Step 1.
To verify, RE-START a CMD shell (restart needed to refresh the environment) and issue:
SET JAVA_HOME JAVA_HOME=c:\Program Files\Java\jdk1.8.0_{xx} <== Verify that this is YOUR JDK installed directory
4. Configure Tomcat Server
The Tomcat configuration files are located in the "conf" sub-directory of your Tomcat installed directory, e.g. "
d:\myProject\tomcat\conf" (for Windows)
server.xml
web.xml
context.xml
tomcat-users.xml
Make a BACKUP of the configuration files before you proceed.
(a) "conf\server.xml" -
[b]Set the TCP Port Number[/b]
Use a programming text editor (e.g., NotePad++, TextPad for Windows; or gEdit, jEdit for Mac OS X) to open the configuration file "
server.xml", under the "
conf" sub-directory of Tomcat installed directory.
The default TCP port number configured in Tomcat is 8080, you may choose any number between 1024 and 65535, which is not used by an existing application. We shall choose 9999 in this article. (For production server, you should use port 80, which is pre-assigned
to HTTP server as the default port number.)
Locate the following lines (around Line 69) that define the HTTP connector, and change
port="8080"to
port="9999".
<!-- A "Connector" represents an endpoint by which requests are received and responses are returned. Documentation at : Java HTTP Connector: /docs/config/http.html (blocking & non-blocking) Java AJP Connector: /docs/config/ajp.html APR (HTTP/AJP) Connector: /docs/apr.html Define a non-SSL HTTP/1.1 Connector on port 8080 --> <Connector port="9999" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
(b) "conf\web.xml" -
[b]Enabling Directory Listing[/b]
Again, use a programming text editor to open the configuration file "
web.xml", under the "
conf" sub-directory of Tomcat installed directory.
We shall enable directory listing by changing "
listings" from "
false" to "
true" for the "
default" servlet. This is handy for test system, but not for production system for security reasons.
Locate the following lines (around Line 103) that define the "default" servlet; and change the "listings" from "
false" to "
true".
<!-- The default servlet for all web applications, that serves static --> <!-- resources. It processes all requests that are not mapped to other --> <!-- servlets with servlet mappings. --> <servlet> <servlet-name>default</servlet-name> <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>0</param-value> </init-param> <init-param> <param-name>listings</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
(c) "conf\context.xml" -
[b]Enabling Automatic Reload[/b]
We shall add the attribute
reloadable="true"to the
<Context>element to enable automatic reload after code changes. Again, this is handy for test system but not for production, due to the overhead of detecting changes.
Locate the
<Context>start element (around Line 19), and change it to
<Context reloadable="true">.
<Context reloadable="true"> ...... ...... </Context>
(d) (Optional) "conf\tomcat-users.xml"
Enable the Tomcat's manager by adding the highlighted lines, inside the
<tomcat-users>elements:
<tomcat-users> <role rolename="manager-gui"/> <user username="manager" password="xxxx" roles="manager-gui"/> </tomcat-users>
This enables the manager GUI app for managing Tomcat server.
5. Start Tomcat Server
The Tomcat's executable programs and scripts are kept in the "bin" sub-directory of the Tomcat installed directory, e.g., "
d:\myProject\tomcat\bin" (for Windows)
(a) Start Server
For Windows
Launch a CMD shell. Set the current directory to "
<TOMCAT_HOME>\
bin", and run "
startup.bat" as follows:
// Change the current directory to Tomcat's "bin" // Assume that Tomcat is installed in "d:\myProject\tomcat" d: // Change the current drive cd \myProject\tomcat\bin // Change Directory to YOUR Tomcat's "bin" directory // Start Tomcat Server startup
(Skip Unless ...) Cannot Start Tomcat: Read "How to Debug".
(b) Start a Client to Access the Server
Start a browser (as HTTP client). Issue URL "
http://localhost:9999" to access the Tomcat server's welcome page. The hostname "
localhost" (with IP address of
127.0.0.1) is meant for local loop-back testing inside the same machine. For users on the other machines over the net, they have to use the server's IP address or DNS domain name or hostname in the format of "
http://serverHostnameOrIPAddress:9999".
![](https://www.ntu.edu.sg/home/ehchua/programming/howto/images/TomcatHomePage.png)
Try issuing URL
http://localhost:9999/examplesto view the servlet and JSP examples. Try running some of the servlet examples.
(Optional) Try issuing URL
http://localhost:9999/manager/htmlto run the Tomcat Web Manager. Enter the username and password configured earlier in
tomcat-users.xml.
(c) Shutdown Server
For Windows
You can shutdown the tomcat server by either:
Press Ctrl-C on the Tomcat console; OR
Run "
<TOMCAT_HOME>\bin\shutdown.bat" script. Open a new "cmd" and issue:
// Change the current directory to Tomcat's "bin" d: // Change the current drive cd \myProject\tomcat\bin // Change Directory to YOUR Tomcat's "bin" directory // Shutdown the server shutdown
WARNING: You MUST properly shutdown the Tomcat. DO NOT kill the cat by pushing the window's "CLOSE" button.
相关文章推荐
- tomcat配置访问项目时不需要加项目名称
- How to Install Apache Tomcat 8 (on Windows, Mac OS X, Ubuntu) and Get Started with Java Servlet Prog
- 使用PSI-probe监控tomcat7
- Tomcat根目录下work文件夹的作用
- Solr6与Zookeeper在Tomcat环境做SolrCloud集群
- tomcat 7.0画面提交数据量大(表单),后台form数据丢失.
- Tomcat实现了哪些规范
- 虚拟机下centos 6/7 配置 jdk1.8 + tomcat9
- Server Tomcat v7.0 Server at localhost failed to start.错误可能原因之一
- 云服务器安装jdk,tomcat
- tomcat启动加载资源两次导致占用内存和CPU
- 部署eclipse+tomcat+spring mvc遇到的若干问题
- eclipse配置tomcat8.5
- 搭建tomcat+Maven
- 设置Tomcat的UTF-8编码
- CentOS6.5 安装 tomcat
- SecureCRT配置Tomcat环境变量
- dubbo管理控制台的安装 【以及】 tomcat启动配置
- 如何优化tomcat配置(从内存、并发、缓存4个方面)优化
- 如何在IntelliJ IDEA中快速配置Tomcat