In this post I will show you the step-by-step instructions to deploy a WAR file in Tomcat 11:
1. Build Your WAR File
A WAR file (.war
) is a packaged web application. To build it:
- If you’re using Maven, run the following command in your project directory:
mvn clean package
This generates a WAR file under the
target/
folder. -
If you’re using other tools (e.g., Gradle, IDE), export the WAR file using the packaging/export option.
2. Install and Configure Tomcat 11
- Download Tomcat 11 from the official website: Apache Tomcat Downloads
- Extract the downloaded ZIP/TAR file to a desired directory.
- Navigate to the
conf/
directory and optionally configure the fileserver.xml
to customize ports, define your hostname, or adjust server parameters (optional for default usage).
3. Start Tomcat
- Navigate to the
bin/
directory. -
Run the startup script as per your operating system:
- On Windows:
startup.bat
- On Linux/Mac:
./startup.sh
- On Windows:
- By default, Tomcat runs on port 8080. Check if it is running by accessing:
http://localhost:8080/
If Tomcat is running, its welcome page should appear.
4. Deploy Your WAR File
You have two primary ways to deploy the WAR file:
a) Manual Deployment
- Copy the WAR file to Tomcat’s
webapps/
directory:- Navigate to the
webapps/
directory inside your Tomcat installation path. - Copy your WAR file (e.g.,
HelloWorld.war
) into this folder.cp /path/to/HelloWorld.war /path/to/tomcat/webapps/
- Navigate to the
- Restart Tomcat:
- Stop and restart Tomcat for new deployments to take effect, using:
shutdown.bat/startup.bat (Windows) ./shutdown.sh && ./startup.sh (Linux/Mac)
- Stop and restart Tomcat for new deployments to take effect, using:
- Access Your Application:
- By default, the application will be available at:
http://localhost:8080/<war-file-name>/
- For example:
http://localhost:8080/HelloWorld/
- By default, the application will be available at:
b) Upload via Tomcat Manager (Web UI)
- Go to the Tomcat Manager application at:
- Log in with your username and password:
- Default username:
admin
- Default password:
admin
(or use the one you set intomcat-users.xml
file underconf/
).
To set new credentials, update theconf/tomcat-users.xml
file by adding:<role rolename="manager-gui"/> <user username="admin" password="admin" roles="manager-gui"/>
- Default username:
- Scroll to the Deploy section:
- Under “WAR file to deploy,” choose the WAR file from your system.
- Click the Deploy button.
- Access Your Application:
- The application URL will be:
http://localhost:8080/<war-file-name>/
- The application URL will be:
5. Check Logs for Errors (if any)
If the application is not working, check Tomcat logs:
- Log files are located in the
logs/
directory of your Tomcat installation. - The most relevant logs include:
catalina.<date>.log
– Main log file for Tomcat.localhost.<date>.log
– Logs specific to deployed applications.
6. Stop Tomcat (if needed)
If you wish to shut down Tomcat:
- Navigate to the
bin/
directory. - Use the shutdown script:
- On Windows:
shutdown.bat
- On Linux/Mac:
./shutdown.sh
- On Windows:
Summary of Key Directories in Tomcat
Directory | Purpose |
---|---|
bin/ |
Contains scripts to start and stop Tomcat. |
conf/ |
Stores configuration files like server.xml . |
webapps/ |
Holds deployed WAR files. |
logs/ |
Contains log files for troubleshooting. |