Você está na página 1de 5

Como criar um projeto JSF no Eclipse com Dynamic Web Project:

Há algumas formas para criarmos um projeto JSF com o Eclipse. Pode ser
através do Maven Project, com ou sem Archetype ( http://www.mauda.com.br/?
p=1937 ). Eu preferi criar através de:

File / New / Dynamic Web Project. Seguem as telas:

Em Configuration, clique em Modify...:


Clique em Next:

Clique em Next:
Clique em Next:

Em seguida, acesse o site do Maven e faça o download de 3 jars para o projeto


JSF:

 jsf-api-2.2.2.jar
 jsf-impl-2.2.2.jar
 jstl-1.2.jar

Cole-as no diretório WebContent/WEB-INF/lib. Clique com o botão direito sobre


os jars e vá em "Build Path" / "Add Build Path".

Em seguida, dentro de WebContent, crie a página index.xhtml.

Veja o resultado:
Agora, clique com o botão direito sobre o Tomcat v9.0 e vá em "Add and
Remove". Adicione o projeto b3. Republish e inicie o servidor. Teste o acesso
com a URL:

Códigos Fontes:

index.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">

<h:head>
<title>Seminarios Academicos</title>
</h:head>
<h:body>
Hello World! <br />
<h:outputLabel value="Exemplo JSF" />
</h:body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID"
version="4.0">
<display-name>b3</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">

</faces-config>

Você também pode gostar