PrimeFaces 5.0 using Eclipse Juno with Maven

You would like to use PrimeFaces for that neat new project you were assigned. You want to ensure that everyone on the team can get the dependencies installed without a hitch, so you naturally choose to use Maven for this. I’ll describe a minimal implementation using Eclipse Juno that will get you started down the path to rich UI using Java.

The relevant links I used for this project are:
PrimeFaces –
PrimeFaces
Example code for PrimeFaces xhtml page –
Getting Started

JSF jars –
JSF-API jar
JSF-IMPL jar

I’ll assume you already have Eclipse installed. I tested this using Eclipse Juno Service Release 2.

Getting Started

Create a new Maven Project in Eclipse.

Screen Shot 2014-08-23 at 10.33.57 AMScreen Shot 2014-08-23 at 10.34.16 AMScreen Shot 2014-08-23 at 10.35.06 AM

You should now see the project in your Project Explorer view. First we’ll want to edit pom.xml to get a few things set up. I am using Java 7 for this project, but you can replace 1.7 with 1.8 in the source and target tags if you feel so inclined.

Screen Shot 2014-08-23 at 10.37.53 AM

Since we are already in pom.xml editing things, let’s add the JSF dependencies.

Screen Shot 2014-08-23 at 10.39.17 AM

We’ve got some error markers now, so we’ll need to fix those.

Screen Shot 2014-08-23 at 10.40.35 AM

You can fix the Maven Problems by updating your Maven Project.

Screen Shot 2014-08-23 at 10.41.24 AM

Alternatively, you could just use the Eclipse Quick Fix feature.

Screen Shot 2014-08-23 at 10.40.53 AM

Now let’s convert this to a faceted project so we can run it on Tomcat. Right click the project in the Project Explorer view and choose Properties -> Project Facets.

Screen Shot 2014-08-23 at 10.42.32 AM Screen Shot 2014-08-23 at 10.43.04 AM

Click OK. Your project will be reconfigured and will now look like this:

Screen Shot 2014-08-23 at 10.43.17 AM

We need to add the Maven Dependencies to the Deployment Assembly. Open the project Properties. You may need to update your maven project and refresh your project for the Maven Dependencies option to become available.

Screen Shot 2014-08-23 at 10.47.01 AMScreen Shot 2014-08-23 at 11.38.53 AMScreen Shot 2014-08-23 at 10.49.48 AMCreate a new File in your WebContent directory. We’ll name this file index.xhtml.

Screen Shot 2014-08-23 at 10.53.08 AMScreen Shot 2014-08-23 at 10.53.33 AM

We’ll use the example code from the PrimeFaces website.

Screen Shot 2014-08-23 at 10.53.48 AM

With that done we can now run this project on the server.

Screen Shot 2014-08-23 at 10.54.14 AMScreen Shot 2014-08-23 at 10.46.26 AMWe are presented with the PrimeFaces spinner UI Component.

Screen Shot 2014-08-23 at 10.54.36 AMGreat Success! You have now set up a new project using PrimeFaces, Maven, and Eclipse. Happy coding!