I was recently setting up a web application running on Tomcat on Windows. What I had to do was the following:

  • Unpack Tomcat in any folder I wanted
  • Copy folder with my web application in ./webapps (shown relative to tomcat root)
  • Set up JRE path in some configuration file for Tomcat
  • Run startup.bat - this produced console window with useful debug output

The Linux case seems to be quite different. After install performed typically through apt, tomcat was already running. It also occupies vast number of different folders across filesystem. The server was started automatically, java or not (I actually don't have Java yet as far as I know) so there's no console output. There must be folder with logs somewhere though.

So my question is how to do with Tomcat what I did on windows. I will need to reproduce that approach, or even automate it. It would actually great if I could make batch installer that would setup Tomcat and my web application - but that's not the question.

  • can you ps -efww | grep tomcat in the linux server and paste the output ? – NewLands Oct 1 '15 at 8:01
  • 1
    What you need to do now is look for Tomcat's root directory and place your web application there. Installing through apt basically automates the steps you mentioned. Go to http://localhost:8080, that should load the default Tomcat page with some links. But if you really wanted to know the "manual" way that is similar to what you did on Windows, take a look at the answer here. It's on Ubuntu, so the commands should be similar on your Debian. – Alaa Ali Oct 1 '15 at 8:04
  • @AlaaAli main part of my quiestion is where do I copy the webapplication and how do I see it was loaded. Because on windows, I could just check that command line window. I'm not necesarily looking for manual approach. Just for the same result as on windows. – Tomáš Zato Oct 1 '15 at 8:15

Automating Deployment of Tomcat

Installation of Tomcat out of the box on linux, or using apt or your package manager of choice is easy; but as you noted it's difficult to know where everything is and what's configured.

I've found the MOST configurable way to automate Tomcat installation on Linux is by using Chef. The ChefDK can be installed, and then using the Tomcat Cookbook for Chef you can configure and deploy chef again and again!

The advantage of installing Tomcat with Chef is a consistent installation of Tomcat in a manner that is standard, supportable, and in-line with the Tomcat documentation for installation on Linux.

Java pre-requisite

The Tomcat cookbook doesn't install Java, so generally I combine the Java Cookbook to automate the installation of your JRE with Tomcat.

Chef Role to install Tomcat

Below is an example Chef Role I have used to deploy JRE and then Tomcat to a linux box.

  • The main two steps that install JRE then Tomcat are in the run_list section of the JSON file
  • The override_attributes section of the Chef role sets the attributes for the Java and Tomcat recipes.
  "name": "java-appserver-small",
  "default_attributes": {},
  "override_attributes": {
    "java": {
      "jdk_version": "7"
    "oracle": {
      "accept_oracle_download_terms": true
    "tomcat": {
      "java_options": "${JAVA_OPTS} -Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m -Xmx3g -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=512m -XX:+DisableExplicitGC -XX:+CMSClassUnloadingEnabled"
  "json_class": "Chef::Role",
  "description": "Role for Java Apps Servers using OpenJDK7 - 15GB Memory",
  "chef_type": "role",
  "run_list": [

It's a little bit of a learning curve, but once you know how to automate anything on linux with chef - it's a great start to rapid re-deployment and automation of anything you can imagine.

Automating deployment of an Application (WAR)

You can add a third recipe to your Chef role that will deploy an application on Tomcat. Generally Tomcat can be configured to auto-unpack and deploy a WAR file.

Modify the run_list in the role to include another recipe:

"run_list": [

Deploy WAR from local file on linux instance

The recipe chef will use app-deploy is a set of instructions to copy a pre-defined WAR file to the Tomcat webapps directory. In the below recipe example, the WAR file path is defined in a from a separate attribute file, but you could hard code the location to copy from as well.

# Cookbook Name:: myChefCookbook
# Recipe:: app-deploy
# This recipe only installs the application.
# Base app server is setup via the java app server role.

# Copy WAR to webapps for auto-deployment
execute "cp #{node['myappfile']} /var/lib/tomcat/webapps/" do
  action :run
  not_if { File.exist?("/var/lib/tomcat/webapps/#{server_file(node['myappfile'])}") }

The recipe copies the WAR file, Tomcat deploys it.

Deploy WAR from AWS S3 bucket to AWS linux instance

The final recipe example below copies (using AWS tools) the WAR file from an Amazon S3 bucket onto the linux instance running Tomcat, deployed by chef, in the Amazon Web Services cloud provider.

# Copy  WAR to webapps for auto-deployment - Requires that the instance have role with access to bucket
execute "aws s3 cp #{node['urls']['myappurl']} /var/lib/tomcat/webapps/" do
  action :run
  not_if { File.exist?("/var/lib/tomcat/webapps/#{server_file(node['urls']['myappurl'])}") }
  • This looks really cool. I just can't find a way to understand how does "accept_oracle_download_terms": true. Is that some built-in thing or is that Chef system so smart? – Tomáš Zato Oct 1 '15 at 8:26
  • It indicates that you accept Oracle's EULA when downloading and installing the Oracle JDK/JRE. Oracle require acceptance; and this is a way of the automation tool noting that the person running it has accepted that. It's a legal thing I guess. Read more here – lantrix Oct 1 '15 at 8:33
  • They note on that link to the cookbook "As of 26 March 2012 you can no longer directly download the JDK from Oracle's website without using a special cookie. This cookbook uses that cookie to download the oracle recipe on your behalf". So this is what that means by setting it to true. – lantrix Oct 1 '15 at 8:34
  • Since I have already deployed both Java and Tomcat I was wondering if you were able to get Chef top also install your web-apps on Tomcat. Because that was primary problem I was trying to solve with my question. – Tomáš Zato Oct 1 '15 at 8:35
  • 1
    Too bad I cannot upvote once more :) – Tomáš Zato Oct 1 '15 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.