Enterprise Java

Creating JSF/CDI Maven project on Eclipse

While I was working on a JSF and CDI example, I thought it would be useful to mention the steps required to create JSF and CDI Maven project. You can find the bellow steps to do so.


  • Eclipse Luna that’s shipped with the M2E plugin by default. So no need to install the plugin yourself.
  • WildFlye 8.x.


  1. Select from the main menu File->New->Other. Then select Maven->Maven Project.

    1-Creating JSF CDI Maven Project

  2. Click the Next button and then check “Create a simple project (skip archetype selection)”.

    2-Creating JSF CDI Maven Project

  3. Write the Group Id and the Artifact Id then select Packaging as WAR.

    3-Creating JSF CDI Maven Project

  4. Click the Finish button to create the project with the bellow structure displayed in the Navigator view.

    4-Creating JSF CDI Maven Project

  5. As you can see there is no deployment descriptor file (web.xml) as there is no WEB-INF folder. Also by checking on the Project Facets (select the project then ALT+ENTER then choose from the left menu Project Facets), we can see that the version of the Dynamic Web Module is 2.5 and the JavaServer Faces is not selected. So it’s time to do some configurations to our project.

    5-Creating JSF CDI Maven Project

  6. Right click on the project name then Configure->Add JSF Capabilities. This will configure the project as JSF project and adds the WEB-INF with the web.xml and the faces-config.xml.

    7-Creating JSF CDI Maven Project

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      <servlet-name>Faces Servlet</servlet-name>
      <servlet-name>Faces Servlet</servlet-name>
    <?xml version="1.0" encoding="UTF-8"?>
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
  7. Adding the necessary API’s as dependencies to the pom.xml. Also, adding the maven-compiler-plugin with version 3.1. I have also pointed maven to use the Java compiler version 1.7. So here is the final pom.xml.
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <name>JSFCDIMavenProject Maven Webapp</name>
  8. Now right click on the project name then choose Maven->Update Project to update the project with the newly added configurations.
  9. The deployment descriptor (web,xml) has version 2.5 and we are pointing to the servlet 3.1 in our dependency. So as per Java EE 7XML schema, the namespace is changed to be http://xmlns.jcp.org/xml/ns/javaee/. This is the final web.xml after applying that change.
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
      <servlet-name>Faces Servlet</servlet-name>
      <servlet-name>Faces Servlet</servlet-name>
  10. Check again the Project Facets. You can change the Dynamic Web Module for the version 3.1 and the JavaServer Faces is checked with version 2.2 as per the version added in the dependencies.

    6-Creating JSF CDI Maven Project

  11. The last configuration that is needed is enabling the CDI context. This could be done by creating an XML file named beans.xml and add it to the WEB-INF folder as the bellow one.
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"

    8-Creating JSF CDI Maven Project

  12. Finally adding the project to WildFly and then starting the server. You will see in the Console view that WildFly started a service for the CDI deployment to the application.

    9-Creating JSF CDI Maven Project

I have pushed this stub project to my GitHub and you can find it through the bellow URL.

Reference: Creating JSF/CDI Maven project on Eclipse from our JCG partner Belal Galal at the I think, I sink! blog.

Want to know how to develop your skillset to become a Java Rockstar?

Join our newsletter to start rocking!

To get you started we give you our best selling eBooks for FREE!


1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design


and many more ....


Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions


Belal Galal

Belal is a full stack Java EE Developer with a good grasp of key skills like Analysis, Architecture and System Administration. He worked in different scale projects in a variety of domains such as inventory management, aerospace, finance, banking and telecom.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Newest Most Voted
Inline Feedbacks
View all comments
Indranil Sharma
Indranil Sharma
4 years ago

Hi ,
After executes i am getting this error .could you please look on it

Servlet [Faces Servlet] in web application [/Demo] threw load() exception
java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet

4 years ago

I already have maven project – using Hibernate/JPA and EJB 3. While am able to test and execute the APIs/classes I have written, now I want to add JSF capabilities to the existing project. How can I add JSF capabilities in Eclipse and maven pom.xml so that I can create web pages in JSF and use the service APIs?

Back to top button