Eclipse JSF/Faclet Support in a Maven Web Project
In the following section I will describe how to configure a Maven Web Module in Eclipse Ganymede to get full support of Content assist, Hover Help and code completion for JSF and Facelets.
These features are supported by the Eclipse Web Tool Platform (WTP). So it seams not to be so difficult to configure a existing web project. But as Maven have some different in building a classpath and updating project configuration in Eclipse you need to be careful to reconfigure a Maven project. I spent a lot of time to find out why it sometimes did not work. So I hope my following walk-through will be helpful to you.
The Situation:
I have an existing Maven Web Project which I checked out from a code repository into my eclipse workspace. Therefor I used the Maven Plugin and the Maven SVN Integration Plugin.
The Maven Project I am working with is a JEE Web module with JSF and Faclets support and also uses the JBoss RichFaces JSF components.So the goal is to get content assist when editing a .xhtml faclets file in my web project.
The Facelets Plugin
To get things run I need first to install the faclets plugin for eclipse. The reason for adding this plugin is that a faclets application typical uses .xhtml pages to represent the jsf resources. The Eclipse WTP did not support .xhml files per deault so the faclets plugin will add the JSF features to also .xhtml files. Additional the plugin includes some wizzards and a new WTP Facete.
You can download the plugin from here. Extract the file and copy the jars into your /plugin folder of your Eclipse Ganymede. Next restart Eclipse!
Adding a JSF Implementation and Server Runntime
Next step is to add a JSF Implementation into you Eclipse Workspace. You can use any Implementation. I take the JSF Implementation form my Glassfish server. There is a Blog where Cay Horstmann explains the details:
http://weblogs.java.net/blog/cayhorstmann/archive/2007/07/jsf_support_in.html
So open the Eclipse preferences dialog and go to Web->JavaServer Faces->Libraries.
Create
a new JSF library and name the library "GlassfishJSF-impl". Add only
the jsf-impl.jar file. This file is located in the /glassfish/lib
folder from your glassfish installation.
Important: Make sure that the option "is JSF Implementation" is checked!
Next add the Server Runtime. Select the Server Node and add your JEE Server (in my case glassfish)

Now Restart you Eclipse!
Add the Server and JSF Libraries to the Java Build Path
Next check the "Java Build Path" settings of your Web Project. You need now to add two libraries to your project.
The Server Runtime Library of Glassfish and the JSF Implementation which added before to the workspace environment.
Click "Add Library..." and select "Server Runtime"

Choose the Glassfish Server from the Server Runtime list. Click finish.
Next I add the JSF Library created before. So click again
"Add library..." and add a JSF Library and select you GlassfishJSF-Impl
created before:

Finally your project library settings should look like this

Add the JSF and Faclets Facets
Next you need to add the Project Facets for JSF 1.2 support and Facelet 1.0. A Facet is a WTP specific feature which adds additional tools and features to a web project. The Facelet 1.0 Facete is an additional feature added by the Facelet plugin I added before.
To add a new Facete you open the preference dialog for your web project and select the "Project facets" node.
If this Node is not present in you project preferences Eclipse has not recognized your Maven web project as a Eclipse Web Project. So you need first to add the WTP Nature to your project manually.
- Switch in the "Navigator" View
- open the file ".project"
- add the nature
<nature>org.eclipse.wst.common.project.facet.core.nature</nature> - save the .project file
Now you can add the different facets in the following order:
- Select Java 5.0
- Select Dynamic Web Module 2.5
after that you can see the link "Further configuration available" - open the dialog
As I am working in a maven project I change the Content and Java Source Directory into
/src/main/webapp
/src/main/java
which are the default maven source folders
Also I unchecked the "Generate deployment descriptor" as my maven project still have the necessary descriptors.
- Next Select "JavaServerFaces 1.2".
Again there is "Further configuration required"
You can select the option "Server Supplied JSF Implementation"
Choose the "Next" Button to switch through the different config pages. - Finally add the "Facelet 1.0 " support.
Again there is "Further configuration available"
I disabled all options as my maven project is well configured - Finally restart eclipse
Now you should have the content assist and hover help in your xhtml files.
Eclipse is parsing all necessary libraries so also my RichFaces tags are now known by Eclipse!
The first time you get the content assist from Eclipse it will take some time as Eclipse needs to analyze the tag libraries. 
If it did not work...
In some cases this did not work. Then the main reason seams to be that the Eclipse java build classpath is not well configured. Check the Java Build Path settings. Remove and add some Libraries - this will help Eclipse to update the Workspace settings and restart Eclipse. Also wait some time after restart until Eclipse have finished all inizalizing.
Posted at 11:04AM May 23, 2009
Posted by: Ralph
Category: General
Posted by ludo on May 23, 2009 at 05:41 PM GMT #
Posted by 192.18.43.225 on May 23, 2009 at 07:16 PM GMT #
Posted by Ralph on May 25, 2009 at 11:03 AM GMT #
* go to "window" > "Preferences..."
* then go to "General" > "Content Types"
* open "Text" and click on "JSP"
* reach the button "Add..." and type ".xhtml"
Also, in preferences window:
* go to "General" > "Editors" > "File Associations"
* find "*.xhtml" and will appear a list of "Associated Editors" below the list of "File Types:"
* hit "Add..." in the "Associated Editors" view (pay attention, there are 2 "Add..." buttons here)
* choose "JSP Editor" and click "OK" and then mark it as default
Now, your .xhtml file will be treated as a .jsp file too.
Regards.
Posted by Thiago dos Santos Prado on August 20, 2009 at 12:53 PM GMT #