How to configure JSF in Tomcat example

18 October 2013
By Gonçalo Marques
In this tutorial we will see how to configure JSF in Tomcat.


Since Tomcat is not a fully fledged Java EE container we must do some additional configuration steps in order to run JSF applications. In this tutorial we will see how to do it.

This tutorial considers the following environment:

  1. Ubuntu 12.04
  2. JDK
  3. JSF 2.2.4
  4. Tomcat 7.0.35

Required Maven dependencies

Following next are the required Maven dependencies:

Required Maven dependencies

<project xmlns="" 






Note that we are including JSF dependency with compile scope (the default scope when dependency's scope is omitted) so it will be included in the application self classpath, ie. it will be bundled with the application. This is needed because Tomcat does not include the JSF runtime by default.

Configuring web.xml

The web.xml configuration we will use is very simple and just configures the Faces Servlet.


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi=""
  id="WebApp_ID" version="3.0">




We are just configuring the Faces Servlet and mapping all requests which URL ends with .xhtml to be handled by the servlet.

A simple JSF managed bean

Now we define a simple JSF managed bean:

package com.byteslounge.jsf.war;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

public class TestBean {

  private String message;

  private void init() {
    message = "JSF is running";

  public String getMessage() {
    return message;


The managed bean has a property - message - that will be shown in the JSF view.

The JSF view

Finally we define a JSF view that will show the message returned by the managed bean:

<!DOCTYPE html>
<html xmlns=""

  <title>JSF running in Tomcat</title>
  <h:outputText value="#{testBean.message}" />

Deploying and testing

Now we put the generated WAR file inside Tomcat's webapps folder. Remember that by default the WAR file name (excluding the .war extension) will be used as the application's context path. In this example we deployed our WAR file as myapp.war

When we access the following URL:


The expected output will be generated by JSF:

JSF application running in Tomcat
JSF running in Tomcat

Download source code from this article

Related Articles


About the author
Gonçalo Marques is a Software Engineer with several years of experience in software development and architecture definition. During this period his main focus was delivering software solutions in banking, telecommunications and governmental areas. He created the Bytes Lounge website with one ultimate goal: share his knowledge with the software development community. His main area of expertise is Java and open source.

GitHub profile:

He is also the author of the WiFi File Browser Android application: