Skip to main content

Tomcat Server

This short guide helps you get oriented with the initial use of a Tomcat server, a very useful tool for developing web applications in Java.

What is Apache Tomcat?​

Apache Tomcat is an open-source web server developed by the Apache Software Foundation. It is designed to run Java-based web applications, specifically Servlets and JavaServer Pages (JSP). Tomcat acts as a Servlet container, managing the execution of these components and facilitating communication between the client (web browser) and the web application.

Tomcat is widely used in the development and deployment of web applications because of its ease of use, flexibility, and compatibility with the Java EE specifications. It provides a robust environment for running dynamic web applications, handling HTTP requests, user sessions, security, and other features that are essential for modern web applications.

Structure of Apache Tomcat​

The general structure of an Apache Tomcat installation is as follows:

apache-tomcat/
├── bin/
├── conf/
├── lib/
├── logs/
├── temp/
├── webapps/
├── work/
└── README.txt

Let's go step by step through what each folder is for and what you will find in it:

  • bin/: Contains the server startup and shutdown scripts, as well as other utilities. Here you will find files such as startup.sh or catalina.bat to start the server.
  • conf/: This is where the server configuration files live, such as server.xml, web.xml, and others. These files are crucial to define how the server behaves and how web applications are configured.
  • lib/: Contains the Java libraries Tomcat needs in order to work. Here you will find .jar files that are essential for the server.
  • logs/: The server logs are stored here, which lets you see the server activity and debug problems.
  • temp/: This folder is used to store temporary files that the server needs while it is running.
  • webapps/: This is where web applications are deployed. You can place your .war files or application folders here so that Tomcat serves them.
  • work/: This folder contains temporary files generated by the server while running web applications. Compiled JSP files and other temporary resources are stored here.
  • README.txt: A text file that provides basic information about Tomcat and how to use it.

What is Catalina?​

Catalina is the Servlet container of Apache Tomcat. It is responsible for handling HTTP requests and running Servlets and JSPs. Catalina manages the lifecycle of Servlets, including their initialization, request handling, and destruction.

Basic Tomcat Commands​

To interact with Tomcat, you can use the following commands from the terminal:

# Start the server
./bin/startup.sh
# Stop the server
./bin/shutdown.sh
# Check the server status
./bin/catalina.sh status
# View the server logs
tail -f logs/catalina.out

These commands let you start, stop, and monitor the status of the Tomcat server, as well as view the activity logs.

How do I configure Tomcat to serve my application?​

To configure Tomcat so that it serves your application, follow these steps:

  1. Create a WAR file: Package your web application into a .war file. You can do this with tools such as Maven or Gradle, or manually if you have the necessary files.
  2. Place the WAR file in the webapps/ folder: Copy your .war file to the webapps/ folder of your Tomcat installation. Tomcat will automatically detect the file and deploy the application.
  3. Configure the server.xml file: If you need to configure specific ports, contexts, or resources, edit the conf/server.xml file. Here you can define your application's context and other parameters.
  4. Start the server: Use the ./bin/startup.sh command to start Tomcat. If everything is configured correctly, your application should be available at http://localhost:8080/your-app.

Self-Assessment Quiz​

Cargando cuestionario...