From the Blogosphere
Creating JavaServer Faces Maven Managed Projects with Eclipse
Projects created this way will open and execute successfully in NetBeans
By: Ken Fogel
Jan. 3, 2014 02:15 PM
Right-mouse click on the project and select Properties and then select Project Facets. You will see:
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:
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.
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:
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.
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.
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.
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
SYS-CON Featured Whitepapers
Most Read This Week