Adding JSF in java project

1

I created a Maven project in IntelliJ IDEA 2016.2, defined it as a Web Application, and later installed JSF.

Before installing JSF, the framework added index.jsp, which works normally, after adding JSF I created a new file called index.xhtml, but when I try to open it Tomcat returns me:

  

HTTP Status 404 -   type Status report

     

message

     

description The requested resource is not available.

     

Apache Tomcat / 9.0.0.M11

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>br.com.blue</groupId>
    <artifactId>Blue</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>1.8</java.version>
        <hibernate.version>5.2.4.Final</hibernate.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <javax.servlet.version>3.1.0</javax.servlet.version>
        <jsf.api.version>2.2.13</jsf.api.version>
        <jsf.impl.version>2.2.9</jsf.impl.version>
        <jstl.version>1.2</jstl.version>
    </properties>


    <dependencies>
        <!-- HIBERNATE -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>

        <!-- JAVAX SERVLET -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${javax.servlet.version}</version>
        </dependency>

        <!-- JSF -->
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>${jsf.api.version}</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>${jsf.impl.version}</version>
        </dependency>

        <!-- JSTL -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl.version}</version>
        </dependency>

    </dependencies>
</project>

    
asked by anonymous 06.11.2016 / 14:13

1 answer

1

Well, I did not understand the dependency version of your JSF. Try replacing the following (or you can choose another one in the maven repository).

<dependency>
    <groupId>javax.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.1</version>
</dependency>

Another thing I noticed is that if it's a Maven project, your views should not be in the webapp folder?

Following the directory logic:

  • src / main / java: package source code organized in packages
  • src / main / resources: resources that the application needs;
  • src / main / webapp: directory for web applications, web.xml, images,
    HTML and XHTM's;
  • src / test / java: unit tests;

Also check that the configuration file web.xml looks like this:

  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>

*.xhtml says that the index to be fetched will be index.xhtml and not .jsp

PS - JSF - Java Server Faces does not install, it's just a specification. It is up to the implementations, such as Mojarra and MyFaces , to make available their libraries that meet this JCP standard.

    
09.11.2016 / 21:20