What is "tomcat"

Tomcat is a Java Web application container server. As a container (container), it simplifies the application code, managing communication, contexts and tasks. In addition, it has management tools and development support.

Container

Web applications do not need to implement communication protocols, such as HTTP and HTTPS. HTTP requests and responses are converted to already validated Java objects and much simpler to use.

Web applications do not need to create contexts to save the state of the applications. There are contexts for storing application variables and user sessions.

Container of web applications

Web applications do not need to create tasks (threads) to be able to handle multiple requests at the same time. Tasks are managed together (pool) by the container and allocated to the processing of applications as required. Applications remain responsible for synchronizing access to shared variables to ensure access in mutual exclusion.

Multiple tasks in web application container

Tools

The Catalina command lets you start and stop Tomcat:

> catalina start

> catalina stop

The System.out of the server applications is redirected to the log file (.../logs/launcher.server.log). This file is very useful during development, especially when errors occur.

The Tomcat admin (http://localhost:8080/admin/) is an alternative to editing configuration files, such as server.xml, tomcat-users.xml, etc..

The Tomcat manager (http://localhost:8080/manager/html) is an application manager. Allows installing (deploy) and remove (undeploy) web applications.

Application management can also be done with the Ant tool.

> ant deploy

> ant redeploy

> ant undeploy

Once installed, web applications are waiting for requests. Resources are requested by URL, in the format:

http://host:port/context-path/alias-path

Where:

  • 'host' is the host’s name or IP address;
  • 'port' is the TCP/IP port (default 80);
  • 'context-path is application name (context);
  • 'alias-path' is the resource name.

'context-path' is defined in build.xml. alias-path is defined in the file web.xml of the application.

Management of applications in Tomcat

Installation

Tomcat can be obtained in http://tomcat.apache.org. There are automatic ways to install it, using Docker, Chocolatey, Homebrew, apt-get and yum.

Installation can be done by unzipping the file (core) in a directory. An environment variable must be defined CATALINA_HOME with the name of the directory where Tomcat was unzipped.

In order to be able to use the deploy automatic provided by Important and exemplified in the available programs, the following lines should be added to the file $CATALINA_HOME/conf/tomcat-users.xml:

<role rolename="manager"/>
<user username="admin" password="adminadmin" roles="manager"/>

The program is launched using the above command.