📜 ⬆️ ⬇️

JSF 2 + Maven + Jetty. Training

Since the last publication of JSF 2, a new version has been released - JSF 2.3.0. This momentous event motivated to write an article. In this part, we will prepare and launch the base application on JavaServer Faces.

Training


Create a new project:

mvn archetype:generate -DinteractiveMode=false -DgroupId=lan.net -DartifactId=habr

Go to the folder habr . Deleting the contents of the ./src/main/java and ./src/test/java folders . We bring ./pom.xml to the following form:

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <!--  jar  war --> <packaging>war</packaging> <groupId>lan.net</groupId> <artifactId>habr</artifactId> <version>1.0-SNAPSHOT</version> <name>habr</name> <url>http://maven.apache.org</url> <dependencies> <!--  API  Jetty. --> <!-- http://www.eclipse.org/jetty/documentation/current/what-jetty-version.html --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> <version>2.3.1</version> <scope>provided</scope> </dependency> <!--  JavaServer Faces 2.3.0 --> <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.faces</artifactId> <version>2.3.0</version> </dependency> </dependencies> <build> <plugins> <!--    . --> <!-- http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html --> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.4.5.v20170502</version> </plugin> </plugins> </build> </project> 

Create folders ./src/main/webapp and ./src/main/webapp/WEB-INF .
In the folder ./src/main/webapp/WEB-INF create the file web.xml :
')
 <?xml version="1.0" encoding="UTF-8"?> <web-app 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-app_3_1.xsd" version="3.1"> <!-- . --> <welcome-file-list> <welcome-file>index.xhtml</welcome-file> </welcome-file-list> </web-app> 

In the folder ./src/main/webapp create the file index.xhtml :

 <?xml version="1.0" encoding="UTF-8"?> <!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>Title</title> </h:head> <h:body> <p>Session ID: <h:outputText value="#{session.id}"/></p> </h:body> </html> 

Run: mvn jetty:run
Checking: http://127.0.0.1:8080/

Afterword



To be continued…

Source: https://habr.com/ru/post/329240/


All Articles