How to deploy a war file in Tomcat 7
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Deploying a WAR (Web Application Archive) file in Apache Tomcat 7 is a straightforward process commonly used by developers to distribute Java-based web applications. Apache Tomcat is a widely-used open-source web server and servlet container that allows you to run Java Servlets and JavaServer Pages (JSP) based applications. In this article, we'll explore the multiple methods to deploy a WAR file in Tomcat 7, and some troubleshooting tips.
1. Preparing Your Tomcat Environment
Before deploying your application, you must first ensure that Tomcat 7 is correctly installed and configured on your server. Download the latest version of Tomcat 7 from the Apache Tomcat website and extract it to a suitable directory on your system.
2. Deployment Methods
There are several methods to deploy a WAR file in Tomcat:
Manually Placing WAR File in the webapps Directory
The simplest method to deploy a WAR file is by directly placing it into the webapps directory of your Tomcat installation. Tomcat will automatically detect the presence of the WAR file and proceed with the deployment. Here's how you can do it:
- Stop the Tomcat server if it's running.
- Copy your WAR file into the
webappsdirectory. - Start the Tomcat server. Tomcat will automatically extract and deploy the application.
Using the Tomcat Manager App
Tomcat includes a web application called Manager App, which provides a UI to manage your applications. To deploy a WAR file using this:
- Ensure the Manager App is configured in
$CATALINA_HOME/conf/tomcat-users.xml. Include user roles such as manager-gui. - Access the Manager App by navigating to
http://<yourserver>:<port>/manager/htmlin your web browser. - Under the "WAR file to deploy" section, choose your WAR file and click the "Deploy" button.
Deployment via Command Line
You can deploy a WAR file using command-line tools:
- Using the
deploycommand with the Tomcat Manager:- Ensure that you have curl or a similar command-line tool.
- Execute a command in the format:
- Using Tomcat's
startup.shandshutdown.sh:- Place your WAR file in the
webappsdirectory. - Use
shutdown.shto stop Tomcat andstartup.shto start it, allowing for new deployments to be picked up.
3. Configuration File: Context.xml
Sometimes, applications require specific configuration. This can be achieved by including a context.xml file in your WAR or under $CATALINA_HOME/conf/[enginename]/[hostname]/ with a .xml file named as the application context path.
4. Monitoring and Troubleshooting
Monitor logs in the $CATALINA_HOME/logs/ directory to check for any potential errors during the deployment process. Common issues might include Java exceptions, missing libraries, or configuration errors in web.xml.
5. Security Considerations
When deploying applications on Tomcat, consider the following security aspects:
- Use strong usernames and passwords for the Manager App.
- Secure Tomcat and your applications with HTTPS.
- Regularly update Tomcat to the latest version to mitigate known vulnerabilities.
Summary Table
Here's a quick reference table to summarize the deployment methods:
| Method | Description | Use Case |
| Direct deployment | Place WAR in webapps and restart Tomcat | Quick testing, small-scale production |
| Tomcat Manager App | Web UI to deploy WAR files | Remote deployment, monitoring |
| Command Line | Use shell scripts or CURL | Automated scripts, systems integration |
Conclusion
Deploying a WAR file in Tomcat 7 can be executed through several methods tailored to different use cases, whether manually, through the Tomcat Manager, or via command-line tools. It's essential to monitor the deployment and configure your environment securely to ensure your application runs smoothly and securely.
Related reading
- How to deploy and serve prediction using TensorFlow from API?
- How to deploy changes to a Cassandra CQL schema
- How to deploy in kubernetes without any changes, just to get pods to cycle
- How to deploy Kafka Stream applications on Kubernetes?
- How to deserialize records from Kafka using Structured Streaming in Java?
- How to determine programmatically the current active profile using Spring boot
- How to deploy Kafka Streaming Application on Kafka Cluster
- How to deploy machine learning algorithm in production environment?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.