DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Using Maven and Without Drools Eclipse Plugin
  • How To Deploy Helidon Application to Kubernetes With Kubernetes Maven Plugin
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline
  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin

Trending

  • Time Series Analysis: VAR-Model-As-A-Service Using Flask and MinIO
  • Spring WebFlux Retries
  • Running End-To-End Tests in GitHub Actions
  • Best Practices for Writing Clean Java Code
  1. DZone
  2. Coding
  3. Frameworks
  4. Creating a JSF/CDI Maven Project on Eclipse

Creating a JSF/CDI Maven Project on Eclipse

How to create a JSF and CDI Maven project in Java using the Eclipse IDE.

Belal Galal user avatar by
Belal Galal
·
Dec. 29, 15 · Tutorial
Like (4)
Save
Tweet
Share
19.51K Views

Join the DZone community and get the full member experience.

Join For Free

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 steps to do so below:

Tools

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

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

2. Click the Next button and then check "Create a simple project (skip archetype selection)".Image title

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

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

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.Image title

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.Image title

<?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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>JSFCDIMavenProject</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<faces-config 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-facesconfig_2_2.xsd"
version="2.2">
</faces-config>

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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ithinkisink</groupId>
<artifactId>JSFCDIMavenProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>JSFCDIMavenProject Maven Webapp</name>

<dependencies>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>JSFCDIMavenProject</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

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"
version="3.1">
<display-name>JSFCDIMavenProject</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>

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.

Image title

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" 
    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/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>

Image title

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.Image title

I have pushed this stub project to my GitHub and you can find it through the below URL.
https://github.com/belalgalal/Blogging/tree/master/JSFCDIMavenProject

Apache Maven Eclipse

Opinions expressed by DZone contributors are their own.

Related

  • Using Maven and Without Drools Eclipse Plugin
  • How To Deploy Helidon Application to Kubernetes With Kubernetes Maven Plugin
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline
  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: