Ahmed Gamal
Ahmed Gamal

Reputation: 1706

IBM BlueMix | While adding jsf : The application or context root for this request has not been found: ./?

I have a simple JSF application running on IBM Bluemix working well with the following J2EE dependencies .

<dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
</dependency>

When replacing it with JSF dependencies

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

I get the following error

The application or context root for this request has not been found: /

Any help?

My Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

  <display-name>Java DB Web Starter</display-name>
  <servlet>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <url-pattern>/api/*</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>index.html</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>

    <!-- Map these files with JSF -->
    <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>*.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>

  <persistence-context-ref>
    <persistence-context-ref-name>openjpa-todo/entitymanager</persistence-context-ref-name>
    <persistence-unit-name>openjpa-todo</persistence-unit-name>
  </persistence-context-ref>

  <resource-ref>
    <!-- The cloudAutowiring-1.0 Liberty feature will resolve this to whatever 
         the database service name is -->
    <!-- When running locally without this feature, create a datasource with 
         the JNDI name "jdbc/mydbdatasource" in server.xml -->
    <!-- If using MySQL locally then use the "url" property and append "?relaxAutoCommit=true", for example: 
         <dataSource id='mysql-datasource' jdbcDriverRef='mysql-driver' jndiName='jdbc/mydbdatasource'> 
         <properties user='root' password='password' url="jdbc:mysql://localhost:3306/db?relaxAutoCommit=true"/> 
         </dataSource> -->
    <res-ref-name>jdbc/mydbdatasource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
  </resource-ref>
</web-app>

Upvotes: 0

Views: 404

Answers (2)

v.bontempi
v.bontempi

Reputation: 1562

Checking on your web.xml you should call your application using

https://[your_application_URL]/faces/

instead of

https://[your_application_URL]/

because the Faces Servlet is listening on this path according to

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

in the same way the jax-rs webservice is listening on the /api path according to

<servlet-mapping>
   <servlet-name>javax.ws.rs.core.Application</servlet-name>
   <url-pattern>/api/*</url-pattern>
</servlet-mapping>

Edit after chatting about the problem:

The problem is with the jsf dependency used, which makes the app to use the jsf-impl-xxx.jar containing classes under java package com.sun.faces, instead of the classes under the package javax.faces loaded with jsf-api-xxx.jar (used when using j2ee-web-api dependency) The classes in this last jar are implementation of standard API defined by JSF specification.

If you would like to add only the dependency for JSF without taking with you the whole j2ee-web-api you could use the artifacts jsf-api-xxx as dependency

It will solve your problem

Upvotes: 1

Ahmed Gamal
Ahmed Gamal

Reputation: 1706

I found the Answer Here

Briefly:

In case you're using Maven, you can find below the necessary coordinates:

Java EE containers (WildFly, JBoss, TomEE, Payara, GlassFish, WebSphere, etc)

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version><!-- 7.0 (JSF 2.2) or 6.0 (JSF 2.0/2.1) --></version>
    <scope>provided</scope>
</dependency>

Note that the Java EE version must match the server's own Java EE version. You can't set it to 7.0 while targeting a Java EE 6 server.

Servletcontainers (Tomcat, Jetty, etc)

Mojarra

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.faces</artifactId>// jsf-imp and jsf-api were been mereged into one jar 
    <version><!-- Check http://javaserverfaces.java.net --></version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>

You can also check org.glassfish:javax.faces repository for current latest Mojarra release version (which is 2.2.13 as of now).

MyFaces

<dependency>
    <groupId>org.apache.myfaces.core</groupId>
    <artifactId>myfaces-api</artifactId>
    <version><!-- Check http://myfaces.apache.org --></version>
</dependency>
<dependency>
    <groupId>org.apache.myfaces.core</groupId>
    <artifactId>myfaces-impl</artifactId>
    <version><!-- Check http://myfaces.apache.org --></version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>

Upvotes: 0

Related Questions