Coming Up for Air

Bootstrapping a JSF 2 project

Monday, January 12, 2009 |

I needed a break this afternoon, so I thought I’d see how easy it is to bootstrap a JSF 2 project. One of the biggest complaints about JSF 1.x is all that XML, so JSF 2 is aiming to fix that. How have we done so far? Based on this quick look (which is my first from-scratch JSF 2 app), really, really well.

Here are the steps I took:

  • Create a web app project using the Maven archetype (because I’m lazy that way : ) :

mvn archetype:create -DartifactId=my-webapp \
  • Add FacesServlet to web.xml:

    <servlet-name>Faces Servlet</servlet-name>
    <servlet-name>Faces Servlet</servlet-name>
  • Add the JSF 2 jars (and their repo) to pom.xml:

        <name> Repository for Maven</name>
  • Create a managed bean:

@ManagedBean(name="main", eager=true)
public class MainBean {
    public MainBean() {
        System.err.println ("MainBean starting up!");
    public String getText() {
        return "Here is some text!";
  • Create the view:

<!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns=""
        <title>Should Not Be Displayed</title>
        <ui:define name="content">
  • Build, deploy, browse

Your web browser should now say "Here is some text!"

Did you notice that all but two of those steps are things you would do for any Java web app? As soon as someone creates a JSF 2 Maven archetype, even that can be simplified. Also notice that there was no mention of faces-config.xml. The application doesn’t have one. Granted, this is an insanely simple application, so the need for faces-config.xml may still arise (navigation comes to mind, but I think we’re working on a simplification for that too).

The rule of thumb seems to be that JSF is not well-suited for smaller, simpler apps where things like Grails, RoR, etc. are a better choice. I think we’ll see that JSF 2 changes that.



    Sample quote

    Quote source


    My name is Jason Lee. I am a software developer living in the middle of Oklahoma. I’ve been a professional developer since 1997, using a variety of languages, including Java, Javascript, PHP, Python, Delphi, and even a bit of C#. I currently work for Red Hat on the WildFly/EAP team, where, among other things, I maintain integrations for some MicroProfile specs, OpenTelemetry, Micrometer, Jakarta Faces, and Bean Validation. (Full resume here. LinkedIn profile)

    I am the president of the Oklahoma City JUG, and an occasional speaker at the JUG and a variety of technical conferences.

    On the personal side, I’m active in my church, and enjoy bass guitar, running, fishing, and a variety of martial arts. I’m also married to a beautiful woman, and have two boys, who, thankfully, look like their mother.

    My Links