Welcome!

Eclipse Authors: PR.com Newswire, Sandi Mappic, Bob Gourley, Michael Bushong, David Smith

Related Topics: Java, XML, Open Source, Eclipse, AJAX & REA

Java: Blog Post

Creating JavaServer Faces Maven Managed Projects with Eclipse

Projects created this way will open and execute successfully in NetBeans

Step 1
Create a project based on my blog “UPDATED Setting up a JEE 6 Web Profile Maven Project in Eclipse using TomEE”.

Step 2
Eclipse reveals its special capabilities such as specialized editors based on the project’s facet. As it now stands the project you just created will allow you to create Servlet/JSP applications. You need to add the JavaServer Faces facet to the project.

Right-mouse click on the project and select Properties and then select Project Facets. You will see:

FacetsBefore

You now need to add the JavaServer Faces facet version 2.1, change the Java version to 1.7 and uncheck JAX-RS. It should now look like:

FacetsAfter

The version of TomEE, 1.6.0, that I am using does not yet have JSF 2.2 in its library. Its current version is 2.1. If you need to use 2.2 then there is a beta version of the library available as of this writing.

Do not click on OK yet.

Step 3
Notice the link just above the buttons that reads “Further configuration required…”. Click on it and you will see:

jsfcapabilitiesbefore

Pull down the combo box at the top labeled “Type:” and select Disable Library Configuration to replace User Library. This is necessary because the JSF libraries are already in the lib folder of TomEE and Maven knows what libraries are required.

It should now look like:

jsfcapabilities

While it is possible to create a JSF application without the JSF servlet deployment descriptor the Eclipse tools use it in some instances. The checkbox must be checked and the values that show in the textboxes can be left as they appear.

Click OK and then OK again.

Step 4
Save all your files. Right mouse click on the project and select Maven -> Update Project. When this is complete you will have errors such as:

errors

The solution was found by entering the first of the Maven Java EE Configuration Problems into Google. “Type Cannot change version of project facet Dynamic Web Module to 2.5.” led me to a Stack Overflow question that pointed out that the <web-app> attributes in the web.xml file needed to be changed. The generated web.xml read:

<?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>JSFExample01</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>

The <web-app> needed to read:

<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_3_0.xsd"
     version="3.0">

Simply put, you need to replace the 2_5 with 3_0 and the 2.5 with 3_0.

Save files and do another Maven->Update Project and the errors all disappear.

Step 5
The errors are gone but a mysterious entry in Markers appears:

error2

Searching for this revealed two solutions. One was to go into Windows -> Preferences -> Java -> Debug and un-select “Suspend execution on uncaught exceptions”. I did this and it made no difference.

The second solution was to right mouse click on the two Unknown descriptions, right mouse click and delete. You are warned that they may come back but in my case after a Maven -> Update Project and a Run -> Maven Build the markers did not return.

You are now ready to create a JavaServer Faces application. Projects created this way will open and execute successfully in NetBeans when the project is saved to a Subversion repository.

Read the original blog entry...

More Stories By Ken Fogel

In 1980 I bought for myself the most wonderful toy of the day, the Apple ][+. Obsession followed quickly and by 1983 I was writing software for small and medium sized businesses in Montreal for both the Apple and the IBM PC under the company name Omnibus Systems. In the evenings I taught continuing education courses that demystified the computer to the first generation of workers who found themselves with their typewriter on the scrap heap and a PC with WordStar taking its place. In 1990 I was invited to join the faculty at Dawson College in the Computer Science Technology program. When I joined the program the primary language was COBOL and my responsibility was to teach small systems languages such as BASIC and C/C++. Today I am now the chairperson and program coordinator of the Computer Science Technology program at Dawson. The program's primary language is Java and the focus is on enterprise programming. I like to write about the every day problems my students and I face in using various languages and platforms to get the job done. And from time to time I stray from the path and write about what I plan to do, what I actually get around to doing, and what I imagine I am doing.