Apache Tomcat is an open-source implementation of the Java Servlet, JavaServer Pages, and Java Expression Language technologies. It is widely used for running Java applications and is compatible with Windows environments. In this article, we will guide you through the process of installing and configuring Apache Tomcat on a Windows system.
Prerequisites
Before you begin, ensure that you have the following:
- A Windows operating system (Windows 10, Windows Server 2016, or later).
- Java Development Kit (JDK) installed. Apache Tomcat requires Java to run. You can download the JDK from the official Oracle website.
Step-by-Step Installation Guide
Step 1: Download Apache Tomcat
- Go to the Apache Tomcat download page.
- Under the "Binary Distributions" section, choose the "32-bit/64-bit Windows Service Installer" link to download the installer.
Step 2: Install Apache Tomcat
- Run the downloaded installer (
apache-tomcat-10.x.x.exe
).
- Follow the installation wizard:
- Click "Next" on the welcome screen.
- Accept the License Agreement and click "Next".
- Choose the components you want to install (default components are usually sufficient).
- Specify the installation location (default is
C:\Program Files\Apache Software Foundation\Tomcat 10.0
).
- Configure the Tomcat ports (default is 8080 for HTTP).
- Provide the path to the JDK installation directory.
- Set up the Tomcat Administrator login credentials.
Step 3: Configure Environment Variables
- Open the Start Menu and search for "Environment Variables".
- Click on "Edit the system environment variables".
- In the System Properties window, click on the "Environment Variables" button.
- Under "System variables", click "New" to create a new variable:
- Variable name:
CATALINA_HOME
- Variable value:
C:\Program Files\Apache Software Foundation\Tomcat 10.0
(or your chosen installation directory)
- Click "OK" to save the new variable.
Step 4: Start Apache Tomcat
- Open Command Prompt (CMD) as an administrator.
- Navigate to the
bin
directory of your Tomcat installation:
cd C:\Program Files\Apache Software Foundation\Tomcat 10.0\bin
- Start the Tomcat server by executing the following command:
startup.bat
- To verify that Tomcat is running, open a web browser and go to
http://localhost:8080
. You should see the Apache Tomcat welcome page.
Example: Deploying a Sample Web Application
- Create a simple Java web application (e.g., a "Hello World" servlet).
- Package the application into a WAR file (e.g.,
HelloWorld.war
).
- Copy the WAR file to the
webapps
directory of your Tomcat installation:
copy HelloWorld.war C:\Program Files\Apache Software Foundation\Tomcat 10.0\webapps\
- Tomcat will automatically deploy the WAR file. You can access your application at
http://localhost:8080/HelloWorld
.
Managing Apache Tomcat via CMD
To stop the Tomcat server, navigate to the bin
directory and execute:
shutdown.bat
To restart the Tomcat server, you can use:
shutdown.bat
startup.bat