Question

I am trying to setup my first maven webapp in jboss dev studio with a jboss application server. The reason I chose these technologies is because this is what we are using at my work. I am a recent graduate, and am trying to get ahead of the game by doing stuff at home. I created a maven-webapp and imported it into jboss dev studio. I grabbed a sample pom.xml and web.xml from http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/

It seems like my server is deploying the war file with the correct files, and the server starts correctly, but I am unable to access the sample .xhtml file.

When I access http://localhost:8080/ it successfully comes up with the jboss portal, but I don't know how to access the index.xhtml file.

Here are my files:

web.xml

    <?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" 
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">

    <display-name>myProject</display-name>

    <!-- Change to "Production" when you are ready to deploy -->
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

    <!-- Welcome page -->
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>

    <!-- JSF mapping -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Map these files with JSF -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

</web-app>

pom.xml

<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>
  <groupId>com.myProject</groupId>
  <artifactId>myProject-web</artifactId>
  <packaging>war</packaging>
  <version>1.0</version>
  <name>myProject-web Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.1.7</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.1.7</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
        </dependency>
                <!-- Tomcat 6 need this -->
        <dependency>
            <groupId>com.sun.el</groupId>
            <artifactId>el-ri</artifactId>
            <version>1.0</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>myProject-web</finalName>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

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:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <title>JSF 2.0 Hello World</title>
    </h:head>
    <h:body>
        <h3>JSF 2.0 Hello World Example - hello.xhtml</h3>
    </h:body>
</html>
Was it helpful?

Solution

The web-app root will be http://<server_name>:<port>/<app-context-root>/ typically app-context-root will be same as war-file-name without .war extention, so for your application web-app root is http://localhost:8080/myProject-web/ assuming that the war file name is myProject-web.war . As mentioned in the toturial you can access you page in following URLs.

http://localhost:8080/myProject-web/index.jsf
http://localhost:8080/myProject-web/index.faces
http://localhost:8080/myProject-web/index.xhtml

because you have mapped the Faces Servlet to *.jsf, *.faces, *.xhtml.

Don't map the Faces Servlet to /* because all the request will go through JSF life cycle.

OTHER TIPS

I changed the way my war file was being deployed to jboss. I changed it to deploy to the jboss deploy folder. I then made a "minimal" web.xml and faces-config.xml file according to site: http://docs.jboss.org/jbossas/6/JSF_Guide/en-US/html_single/#web-xml

Now that I have a base maven jsf webapp running on jboss. I will look into optimizing everything.

The url I needed to access was:

http://localhost:8080/collegecellar-web/index.xhtml

I used the same MyKong JSF application with these following settings :

In the web.xml

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

In the pom.xml

<dependencies>
  <dependency>
    <groupId>javax.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.0</version>
    <scope>provided</scope>
  </dependency>
</dependencies>
<repositories>
  <repository>
    <id>java.net.m2</id>
    <name>java.net m2 repo</name>
    <url>http://download.java.net/maven/2</url>
  </repository>
</repositories>

And the url :

http://localhost:8080/JavaServerFaces/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top