JSF 2 Installation and Configuration Using Maven 3

JavaServer Faces (JSF) is a server side component framework for building Java Technology web-based application. JavaServer Faces (JSF) consists of two main parts:

  • The JavaServer Faces API for representing components, managing their states, handling events, handling server side validations, and achieving data conversion; defining pages navigation, supporting internationalization and accessibility and providing extensibility for all these features.
  • Tag libraries for adding components to the web pages and connecting those components into their corresponding server side objects.

This post should clarify how a JSF framework could be installed and configured by using Eclipse IDE and Maven.

Also Read:

Tools Used

This post will use the following tools for achieving the required installation and configuration:

Create JSF Project With Maven

To create a Web Project using maven, you should use the maven archetype. The Archetype is a template toolkit that used for creating a standard Java projects. Those templates are used to create several types of Java projects starting from a standard simple Java into very complicated Enterprise application.

Creating a maven Web Project should follow these steps mentioned below:

  • Download the latest maven-archetypes-templates from an official “Github” site Maven Archetypes Zip File using the “Download Zip” link that’s appended at the right panel of the page.
  • Unzip the file inside an empty folder and navigate into quickstart-web-app folder and execute the following maven commands to install the template that will be used to create a simple standard Web Project:
    1. Execute mvn clean archetype:create-from-project. The result of execution should be a new template that must be installed on your local repository to be used later.
    2. Navigate to “target/generated-sources/archetype” and execute mvn install to install the created template into your local repository.
    3. Navigate into an empty folder and execute mvn archetype:generate -DarchetypeCatalog=local -DgroupId=net.javabeat.eclipselink –DartifactId=EclipseLink-Installation -Dversion=1.0
    4. A list of local archetype will be listed if you have different archetypes that have been created.
    5. Enter the number beside of the archetype named “quickstart-web-app-archetype”.
    6. List all folders that created in a step 3 by using dir or ls based on your Os. You should see the artifact JavaBeat-JSF-Installation.
    7. The JavaBeat-JSF-Installation is a standard Web Project that created by the maven. The created project contains your own named package that passed in the -DgroupId.

See the below screen shot that shows you the created project and its structure.

JSF Maven Structure Directory

Import Maven Web Project Into Eclipse IDE

Eclipse IDE provides the developer capability of importing a maven project through an eclipse driven wizard. Follow the following steps to import the project created previously.

  1. Open EclipseIDE.
  2. Right-Click at the “Project Explorer”.
  3. Choose import option and from the right menu click import.
  4. Expand the maven tree.
  5. Choose Existing Maven Projects. And click next.
  6. Navigate into your created project by using the browse and click ok. In our case the path is C:\JavaBeat\archetype.
  7. The Eclipse IDE should read the pom.xml and tell you with the name of the projects found there.
  8. In our case the Eclipse IDE will mention /JavaBeat-JSF-Installation/pom.xml.
  9. Select the project & click finish.
  10. The Web Project should be imported.

The below snapshot shows you the full structure of the imported directory.

Full Maven Imported Project for JSF

At the end of the previous steps, you are now having a Dynamic Web Project that’s ready for next coming installation and configuration of JavaServer Faces (JSF). 

Add JSF Dependencies

If you’ve want to complete adding the JavaServer Faces required library by using a faceted project you can follow the link of installation and configuration of JavaServer Faces using the Facet Dynamic Web Project using Eclipse.

But here’s an adding of the required libraries should be done through the maven dependencies. First of all we have to configure the pom.xml in order to support the JavaServer Faces (JSF). To configure the pom.xml file you’ve to follow the below steps:

  • Double click on the pom.xml file.
  • Navigate into the pom.xml pane that located at the last Tab.
  • Maven dependencies for JavaServer Faces are mentioned at the following link and use the Mojarra Sun’s Reference Implementation.

Add the following dependencies inside the <dependencies> Tag:








Installing the Dependencies

For installing the dependencies that you’ve mentioned in the pom.xml file you have two choice:

  • By invoking the Eclipse IDE Build Project Shortcut Ctrl + B.
  • By invoking the Maven clean install command.

The below snapshots shows you the behavior for each way of installing respectively.

Installing Dependencies By Eclipse

Installing Dependencies By Maven

Configure the Deployment Descriptor (web.xml)

The web.xml file should be configured to make the application capable of invoking the JavaServer Faces (JSF) implementation. Such that configuration should consider the following points:

  • Configure the JavaServer Faces Front Servlet that would be used by the JavaServer Faces implementation and the mapping URL that would be used for triggering that Servlet.
  • Configure the location of the faces-config.xml file that will be used for defining the Managed Beans, Navigation Cases and Custom Components (Validator, Converter and etc ..)
  • Configure the location that will be used for saving the state of the view components.
  • Configure the JavaServer Faces Listener.

The web.xml file should looks like the below

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 id="WebApp_ID" version="2.5" metadata-complete="true">
 <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
 <servlet-name>Faces Servlet</servlet-name>
 <servlet-name>Faces Servlet</servlet-name>
 <servlet-name>Faces Servlet</servlet-name>

Creating Managed Bean

The Managed bean is the place that you’ve used for managing the data back and forth between the user interface and the server. At the Hello World example we are going to define a new Manged Bean in order to make a Hello World ! message readable from the server side instead of mentioning it directly at the page. Before JavaServer Faces 2, the creation of managed server does need a faces-config.xml to mention it.

To create a managed bean, all you need is to do the following:

  • Right Click on the package named net.javabeat.jsf
  • Select New -> Class.
  • Change the name of the class.
  • Define new property helloProperty.
package net.javabeat.jsf;

public class HelloWorldBackingBean {
 private String helloProperty = "Hello World !";

public String getHelloProperty() {
 return helloProperty;

public void setHelloProperty(String helloProperty) {
 this.helloProperty = helloProperty;

Configure faces-config.xml

The faces-config.xml file should also be configured to contains those managed beans that would be used in the JavaServer Faces pages. The below fragment of code shows you the full faces-config.xml for the Hello World application, in case you’ve decided to define your beans in the face-config.xml. Since JavaServer Faces 2 the beans are defined using the annotation of @ManagedBean.

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"

By the way, the following fragment of code will show you the JavaServer Faces (JSF) beans defined using @ManagedBean. The managed bean that created is simply a java class file annotated using @ManagedBean and by that the JavaServer Faces implementation will scan your classpath for finding those classes annotated @ManagedBean.

package net.javabeat.jsf;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

public class HelloWorldBackingBean {
 private String helloProperty = "Hello World !";

public String getHelloProperty() {
 return helloProperty;

public void setHelloProperty(String helloProperty) {
 this.helloProperty = helloProperty;

Configure Apache Tomcat

If you’ve ever been configured the Apache Tomcat for executing a JSF samples, you’ve requested to install and configure it for next coming use. Follow the below steps for making Apache Tomcat for use.

  • From the dynamic project and underneath of Target Runtime -> Select New Runtime

New Runtime

  1. Select Apache Tomcat v7.0 -> Click Next
  2. Type the name of the server that you’ve been installing.
  3. Navigate into the destination path of the Apache Tomcat 7.0 (Download the Apache Tomcat 7.0).
  4. Click on the server pane by Window -> show view -> Servers or Other -> Servers.
  5. You should find the following message (No Servers are available. Click this link to create a new server …)
  6. Choose Tomcat 7.0
  7. Let’s the remaining configuration without touch.
  8. Click next and finish.

Adding of Apache Server

  • The server is installed and is ready for use

Create JavaServer Faces Page

After creating, configuring and installing the all libraries that required to start using of JavaServer Faces, it’s time to create the first Hello World sample.

  • Right-Click the project’s WebContent.
  • Select New -> HTML File.
  • Name your file with an index.xhtml -> Click Next
  • Select New XHTML File (1.0 strict) -> Click Finish
  • Write a JavaServer Faces fragment of code for using the defined bean.
  • The HelloWorldBackingBean contains an attribute with a getter and setter (This is a JSF constraint for showing the bean’s properties).
  • A new property defined in the HelloWorldBackingBean called (helloProperty) with a default value Hello World !.

The page that you will create it must be as below

<html xmlns="http://www.w3.org/1999/xhtml"
 <h:outputText value="#{helloWorldBackingBean.helloProperty}"></h:outputText>

Run index.xhtml

To run the index.xhtml you should follow the below steps:

  • Righ-Click on the index.xhtml
  • Select Run As
  • Select the configured Apache Server that you’ve done before.
  • Click finish.
  • You should see the message Hello World !

Download Source Code

What’s The Next

After finishing the installation and configuration of JSF 2, you have the chance to go through another tutorials that clarify you how a different types of JSF componenets could be used.

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!