- In eclipse, Window/Show View/Servers
- If you have a working Tomcat in Eclipse, go to step 6.
- Download and unzip Tomcat 9 anywhere on your computer.
- If this is a new Eclipse and no Tomcat is already in the Servers tab window, right click on that window, select New Server. Select Tomcat vX.x Server which is the version Tomcat you downloaded and unzipped. Click Next
- Click Browse to fill in the directory where you downloaded Tomcat. Click finish.
- In Eclipse, create a new Dynamic Web Project; here is one way: File / New / Project / Web / Dynamic Web Project. Next.
- ProjectName: JsfTut. Configuration: Click Modify button. (On old versions of Eclipse, we just selected the Jsf2.2 config, no modify, no save). Select Java Server Faces v2.2. Click Save As. Name it MyJsf2.2Config. You’ll be using this config in future JSF projects.
- Hit Next until you get to the JSF Capabilities screen.
- Type: User Library. Below it, right click (or click the download button beside it) and download library for JSF 2.2. Also before clicking finish, highlight *.faces and click the Remove button to remove any mapping patterns that are there. Click the Add button and add *.jsf Now click finish.
- In Project Explorer, expand your new project. Navigate to WebContent/WEB-INF, and right-click on web.xml. Open With/Text Editor.
- Add the lines listed below into web.xml just before the web-app closing tag
- Now we’ll create a home page of type xhtml. Right-click on the project name in Project Explorer: JsfTut. New/Html File/index.xhtml. Click finish. Delete its contents and replace them with the contents in the second piece of code below
- It’s ready to run. Eclipse can show the web page but it will take a minute. Right click on the project name (JsfTut)/ Run As/Run on Server/ Select the Tomcat Version and proceed. In Eclipse, the web page should say “Congrats this works”. If it worked for you, show some luv, and leave a comment below. 🙂
Congrats, this works!
<context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> <param-value>Development</param-value> </context-param> <welcome-file-list> <welcome-file>index.jsf</welcome-file> <welcome-file>welcome.jsf</welcome-file> <welcome-file>index.html</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html"> <h:head> <title>JsfTut</title> </h:head> <h:body> <h1>Congrats, this works!</h1> </h:body></html>