Apache Tomcat Hands-On


Apache Tomcat, often referred to simply as Tomcat, is an open-source web server and servlet container developed by the Apache Software Foundation. It is one of the most popular Java-based web application servers used for deploying and running Java servlets and JavaServer Pages (JSP).
Tomcat is designed to be lightweight and easy to use, making it a popular choice for developers and organizations looking to deploy Java web applications. Tomcat is widely used in both development and production environments and is compatible with various operating systems, including Windows, Linux, and macOS.
Why we use Apache Tomcat?
Apache Tomcat is a popular open-source web server and servlet container used to deploy and run Java web applications. Here are some reasons why people use Apache Tomcat:
Lightweight: Apache Tomcat is relatively lightweight compared to other application servers like WebLogic or WebSphere. It has a small footprint and requires less system resources, making it an ideal choice for development and testing environments as well as for smaller-scale production deployments.
Standards-compliant: Apache Tomcat is a certified implementation of the Java Servlet, JavaServer Pages (JSP), and Java Expression Language (EL) specifications. This ensures that web applications developed using these specifications will run correctly on Tomcat.
Easy to configure: Apache Tomcat is known for its simple and straightforward configuration. It includes a built-in web-based management interface that allows administrators to easily configure and manage the server.
Open-source: Apache Tomcat is an open-source project, which means that it is free to use and distribute. This makes it an attractive option for organizations with limited budgets or those who prefer community-driven development.
Extensible: Apache Tomcat is highly extensible, with a large number of third-party libraries and connectors available. This allows developers to easily integrate Tomcat with other technologies such as databases, security frameworks, and messaging systems.
Integration with other Apache projects: Tomcat integrates well with other Apache projects such as Apache HTTP Server, Apache Struts, and Apache Maven, making it an even more powerful and versatile platform for developing and deploying Java web applications.
Real World Scenario
One real-world scenario where Apache Tomcat is commonly used is in the deployment of enterprise web applications. Let's consider an example of an e-commerce website.
Development: The development team builds a Java-based e-commerce web application using servlets and JSPs. They use Apache Tomcat as the target runtime environment during development, allowing them to test and debug the application locally.
Testing: Testers can deploy the application on a dedicated Tomcat server or use a shared Tomcat instance for testing purposes.
Staging: After successful testing, the application moves to the staging environment, where it is deployed on a dedicated Tomcat server that closely resembles the production environment.
Production Deployment: Once the application passes all the required tests and validations, it is ready for deployment to the production environment. In the production setup, Tomcat is configured to handle the incoming web requests and serve the dynamic content generated by the application.
Scalability and Load Balancing: As the e-commerce website gains popularity and experiences increased traffic, the need for scalability arises. Tomcat's clustering and load balancing capabilities come into play. Multiple Tomcat instances are set up and configured in a cluster, and a load balancer is placed in front of them. The load balancer distributes incoming requests across the cluster, ensuring high availability, fault tolerance, and efficient utilization of server resources.
Monitoring and Management: Tomcat's built-in monitoring and management features are utilized to monitor the performance and health of the production environment.
Security: Tomcat provides various security mechanisms to protect the e-commerce website. It supports SSL/TLS encryption to secure data transmission between clients and the server.
In this real-world scenario, Apache Tomcat serves as the underlying web server and servlet container, providing a reliable and scalable platform for hosting the e-commerce website. Its features and capabilities ensure efficient deployment, management, and secure operation of the Java-based web application throughout its lifecycle.
Commands To Setup:
##################----INSTALL TOMCAT----##################
cd /opt
sudo wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.65/bin/apache-tomcat-9.0.65.tar.gz
sudo tar -xvf apache-tomcat-9.0.65.tar.gz
cd /opt/apache-tomcat-9.0.65/conf
sudo vi tomcat-users.xml
# ---add-below-line at the end (2nd-last line)----
# <user username="admin" password="admin1234" roles="admin-gui, manager-gui"/>
sudo ln -s /opt/apache-tomcat-9.0.65/bin/startup.sh /usr/bin/startTomcat
sudo ln -s /opt/apache-tomcat-9.0.65/bin/shutdown.sh /usr/bin/stopTomcat
sudo vi /opt/apache-tomcat-9.0.65/webapps/manager/META-INF/context.xml
comment:
<!-- Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
sudo vi /opt/apache-tomcat-9.0.65/webapps/host-manager/META-INF/context.xml
comment:
<!-- Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
sudo stopTomcat
sudo startTomcat
sudo cp target/*.war /opt/apache-tomcat-9.0.65/webapps/
After copying the Artifact in webapps folder we can see the deployed application.
Subscribe to my newsletter
Read articles from Bittu Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Bittu Sharma
Bittu Sharma
Hi, This is Bittu Sharma a DevOps & MLOps Engineer, passionate about emerging technologies. I am excited to apply my knowledge and skills to help the organization deliver the best quality software products. β’ π¦πΌπ³π π¦πΈπΆπΉπΉπ ππ²π'π ππΌπ»π»π²π°π I would love the opportunity to connect and contribute. Feel free to DM me on LinkedIn itself or reach out to me at bittush9534@gmail.com. I look forward to connecting and networking with people in this exciting Tech World.