Deploy a WAR file of a Java web application on the Apache Tomcat web server

There are two ways to deploy a WAR file of a Java web application on the Apache Tomcat web server

Using the command line

  1. Copy the WAR file into the webapps folder of the Tomcat installation directory,
  2. Make sure the CATALINA_HOME environment variable points to the Tomcat directory (not the bin subdirectry)
  3. Open a Terminal window or Command Prompt,
  4. Navigate to the bin directory of the Tomcat web server installation directory,
  5. Execute
    startup
  6. Tomcat will unzip the war file into a directory named after the WAR file and display the message similar to this.

    C:\Program Files\apache-tomcat-8.5.23\bin>startup
    Using CATALINA_BASE: “C:\Program Files\apache-tomcat-8.5.23”
    Using CATALINA_HOME: “C:\Program Files\apache-tomcat-8.5.23”
    Using CATALINA_TMPDIR: “C:\Program Files\apache-tomcat-8.5.23\temp”
    Using JRE_HOME: “C:\Program Files\Java\jre-9.0.1”
    Using CLASSPATH: “C:\Program Files\apache-tomcat-8.5.23\bin\bootstrap.jar;C:\Program Files\apache-tomcat-8.5.23\bin\tomcat-juli.jar”C:\Program Files\apache-tomcat-8.5.23\bin>

Using the Tomcat user interface

  1. Remote into the web server,
  2. Copy the WAR file to a temp directory,
  3. Open the Tomcat web user interface at http://localhost:8080/manager
  4. Log in with the credentials specified for the manager-gui role in the tomcat-users.xml file of the conf Tomcat folder,
  5. In WAR file to deploy section click the Choose File button and select the WAR file,
  6. Click the Deploy button,
  7. Tomcat will unzip the war file into a directory named after the WAR file in the webapps folder of the Tomcat installation directory.

Tomcat web server configuration

When you install the Apache Tomcat web server there are some configuration settings you need to make to be able to administer and use it.

Administrator user accounts

When you install the Apache Tomcat web server there is no admin user account specified, so nobody can log into the admin web user interface. To add an admin user account

  1. Remote into the web server
  2. Open the Tomcat user configuration file at
    1. On Linux at $TOMCAT_HOME/conf/tomcat-users.xml
    2. On Windows at C:\Program Files\apache-tomcat-…\conf\tomcat-users.xml
  3. Add an admin user
    <tomcat-users>
    <!--
      <role rolename="tomcat"/>
      <role rolename="role1"/>
      <user username="tomcat" password="tomcat" roles="tomcat"/>
      <user username="both" password="tomcat" roles="tomcat,role1"/>
      <user username="role1" password="tomcat" roles="role1"/>
    -->
    
    	<role rolename="manager-gui"/>
    	<user username="admin" password="admin" roles="manager-gui"/>
    
    </tomcat-users>
  4. Restart the Tomcat service for the change to take effect.

Firewall

With the default settings, Tomcat is accessible on port 8080. To be able to use the web applications served by Tomcat, open port 8080 on the local firewall.

Tomcat web server installation

Tomcat is one of the most popular free web servers. Tomcat runs on the Linux, Macintosh, and Windows operating systems.

To install Tomcat

Install the Java Runtime Environment (JRE)

  1. Download the Java JRE from http://www.oracle.com/technetwork/java/javase/downloads/index.html
  2. Install the Java JRE

On Windows

  1. Execute the downloaded .exe file
  2. Create an environment variable to point to the installed Java
    1. If you installed the Java JDK (Java Development Kit)
      1. JAVA_HOME=c:\Program Files\Java\jdk-…
    2. If you installed the JRE (Java Runtime Environment)
      1. JRE_HOME=C:\Program Files\Java\jre-…

 

Install Tomcat

  1. Download the Tomcat installer from https://tomcat.apache.org/
  2. To select the right file to download read the explanation on the page linked to “Please see the README file for packaging information”.

On Windows

Select the installer based on the operating system and the Java environment you want to run:

  • 32 bit Java Virtual Machine on32 bit or 64 bit Windows: apache-tomcat-[version]-windows-x86.zip
  • 64 bit Java Virtual Machine on 64 bit Windows: apache-tomcat-[version]-windows-x64.zip
  1. Unzip the downloaded archive and move the apache-tomcat-x.x.x directory to C:\Program File
  2. Create the Tomcat environment variable
    CATALINA_HOME=C:\Program Files\apache-tomcat-x.x.x

Start Tomcat

  1. Open a terminal or console in the Tomcat bin directory
  2. Execute
    startup
  3. Enable the access to the Tomcat server through the firewall
    1. On Windows

Test Tomcat

  1. Open a web browser on the server and navigate to http://localhost:8080/
  2. You should see the Tomcat default page

Auto start Tomcat

If you want to use Tomcat as a web server, it should start automatically when the computer starts.

On Windows

  1. Open a command prompt in the tomcat bin directory
  2. Execute
    service.bat install
  3. On the User Account Control popup click the Yes button
  4. The last message in the command prompt should say

    The service ‘Tomcat..’ has been installed.

  5. Open  Services and select the Apache Tomcat service
  6. Set the Startup type to Automatic, click the Start button to start the service, and click OK.

 

Cannot restart the Atlassian Confluence service on Windows

When the Atlassian Confluence wiki is installed on a Windows server, it frequently becomes unavailable. Sometimes it is possible to restart the Atlassian Confluence Windows service, but most of the time the Stop phase times out with:

Windows could not stop the Atlassian Confluence service on Local Computer.
Error 1053: The service did not respond to the start or control request in a timely fashion.

To make Atlassian Confluence work again

  1. Open Task Manager,
  2. End the tomcat…exe process,
  3. Start the Atlassian Confluence Windows service.