How to Install Tomcat (Follow if Jenkins is Executing on Windows Only)
I shall assume that you have created a directory called "c:\myWebProject
" (for Windows) or "~\myWebProject
" (for Mac OS X) in your earlier exercises. Do it otherwise. This step is important; otherwise, you will be out-of-sync with this article and will not be able to find your files later.
For Windows
Goto http://tomcat.apache.org ⇒ Under "Tomcat 9.0.{xx} Released", where {xx} is the latest update number ⇒ Click "Download" ⇒ Under "9.0.{xx}" ⇒ Binary Distributions ⇒ Core ⇒ "zip
" (e.g., "apache-tomcat-9.0.{xx}.zip
", about 11 MB).
UNZIP the downloaded file into your project directory "c:\myWebProject
". Tomcat shall be unzipped into directory "c:\myWebProject\apache-tomcat-9.0.{xx}
".
For EASE OF USE, we shall shorten and rename this directory to "c:\myWebProject\tomcat
".
Take note of Your Tomcat Installed Directory. Hereafter, I shall refer to the Tomcat installed directory as <TOMCAT_HOME>
.
For Mac OS X
Goto http://tomcat.apache.org ⇒ Under "Tomcat 9.0.{xx} Released", where {xx} is the latest update number ⇒ Click "Download" ⇒ Under "9.0.{xx}"⇒ Binary distribution ⇒ Core ⇒ "tar.gz
" (e.g., "apache-tomcat-9.0.{xx}.tar.gz
", about 10.5 MB).
To install Tomcat:
Double-click the downloaded tarball (e.g., "apache-tomcat-9.0.{xx}.tar.gz
") to expand it into a folder (e.g., "apache-tomcat-9.0.{xx}
").
Move the extracted folder (e.g., "apache-tomcat-9.0.{xx}
") to your project directory "~/myWebProject
".
For EASE OF USE, we shall shorten and rename this folder to "tomcat", i.e., "~/myWebProject/tomcat
".
Take note of Your Tomcat Installed Directory. Hereafter, I shall refer to the Tomcat installed directory as <TOMCAT_HOME>
.
Take a quick look at the Tomcat installed directory. It contains the these sub-directories:
bin: contains the binaries and scripts (e.g., startup.bat
and shutdown.bat
for Windows; startup.sh
and shutdown.sh
for Unixes and Mac OS X).
conf: contains the system-wide configuration files, such as server.xml
, web.xml
, and context.xml
.
webapps: contains the webapps to be deployed. You can also place the WAR (Webapp Archive) file for deployment here.
lib: contains the Tomcat's system-wide library 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.
work: Tomcat's working directory used by JSP, for JSP-to-Servlet conversion.
(For Windows)
You need to create an environment variable (system variable available to all applications) called "JAVA_HOME
", and set it to your JDK installed directory.
Follow the steps HERE!
(For Mac OS)
Skip this step. No need to do anything.
The Tomcat configuration files, in XML format, are located in the "conf
" sub-directory of your Tomcat installed directory, e.g. "c:\myWebProject\tomcat\conf
" (for Windows) or "~/myWebProject/tomcat/conf
" (for Mac OS X). The important configuration files are:
server.xml
web.xml
context.xml
Make a BACKUP of the configuration files before you proceed!!!
Use a programming text editor (e.g., Sublime Text, Atom) to open the configuration file "server.xml
".
The default TCP port number configured in Tomcat is 8080, you may choose any number between 1024 and 65535, which is not used by existing applications. 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 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="9090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
The Tomcat's executable programs and scripts are kept in the "bin
" sub-directory of the Tomcat installed directory.
For Windows
I shall assume that Tomcat is installed in "c:\myWebProject\tomcat
". Launch a CMD shell and issue:
c: // Change drive cd \myWebProject\tomcat\bin // Change directory to your Tomcat's binary directory startup // Run startup.bat to start tomcat server
For Mac OS
I assume that Tomcat is installed in "~/myWebProject/tomcat
". To start the Tomcat server, open a new "Terminal" and issue:
cd ~/myWebProject/tomcat/bin // Change directory to your Tomcat's binary directory ./catalina.sh run // Run catalina.sh to start tomcat server
A new Tomcat console window appears (with Java's coffee-cup logo as icon). Study the messages on the console. Look out for the Tomcat's port number. Double-check that Tomcat is running on port 9090 is configured.
Error messages will be sent to this console. System.out.println()
issued by your Java servlets will also be sent to this console.
............ ............ xxxxx INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-9999"] xxxxx INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"] xxxxx INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [1325] ms
For Windows
You can shut down 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:
c: // Change the current drive cd \myWebProject\tomcat\bin // Change directory to your Tomcat's binary directory shutdown // Run shutdown.bat to shutdown the server
For Mac OS
To shut down the Tomcat server:
Press Control-C (NOT Command-C) on the Tomcat console; OR
Run the "<TOMCAT_HOME>/bin/shutdown.sh
" script. Open a new "Terminal" and issue:
cd ~/myWebProject/tomcat/bin // Change current directory to Tomcat's bin directory ./shutdown.sh // Run shutdown.sh to shutdown the server
WARNING: You MUST properly shutdown the Tomcat. DO NOT kill the CAT by pushing the window's "CLOSE" button.