title: JSF managed bean in Maven project: Target Unreachable, identifier 'bean' resolved to null
body: <p>Target unreachable error is coming, somehow my bean is not initializing and the value of the bean is coming null. My helloBean reference is coming null. </p>
  
  <p>POM.xml</p>
  
  <pre><code>&lt;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"&gt;
   &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
   &lt;groupId&gt;com.rout.sagar&lt;/groupId&gt;
   &lt;artifactId&gt;DemoMavenJAVAEE&lt;/artifactId&gt;
   &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;DemoMavenJAVAEE Maven Webapp&lt;/name&gt;
  &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  &lt;dependencies&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;junit&lt;/groupId&gt;
    &lt;artifactId&gt;junit&lt;/artifactId&gt;
    &lt;version&gt;3.8.1&lt;/version&gt;
    &lt;scope&gt;test&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.sun.faces&lt;/groupId&gt;
      &lt;artifactId&gt;jsf-api&lt;/artifactId&gt;
      &lt;version&gt;2.1.7&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.sun.faces&lt;/groupId&gt;
      &lt;artifactId&gt;jsf-impl&lt;/artifactId&gt;
      &lt;version&gt;2.1.7&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
      &lt;artifactId&gt;jstl&lt;/artifactId&gt;
      &lt;version&gt;1.2&lt;/version&gt;
  &lt;/dependency&gt;
  
  
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
          &lt;version&gt;2.5&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
          &lt;artifactId&gt;jsp-api&lt;/artifactId&gt;
          &lt;version&gt;2.1&lt;/version&gt;
      &lt;/dependency&gt;
              &lt;!-- Tomcat 6 need this --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.sun.el&lt;/groupId&gt;
          &lt;artifactId&gt;el-ri&lt;/artifactId&gt;
          &lt;version&gt;1.0&lt;/version&gt;
      &lt;/dependency&gt;
  
   &lt;/dependencies&gt;
   &lt;build&gt;
  &lt;finalName&gt;DemoMavenJAVAEE&lt;/finalName&gt;
  
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>HelloBean.java</p>
  
  <pre><code>package com.rout.sagar;
  
     import javax.faces.bean.ManagedBean;
     import javax.faces.bean.SessionScoped;
     import java.io.Serializable;
  
     @ManagedBean
     @SessionScoped
     public class HelloBean implements Serializable{
  private static final long serialVersionUID = 1L ; 
  private HelloBean hello ;
  
  private String name ; 
  public String getName() {
      return name ;
  }
  
  public void setName(String name) {
      this.name = name ;
  }}
  </code></pre>
  
  <p>Web.XML</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;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"&gt;
  
  &lt;display-name&gt;DemoMavenJAVAEE&lt;/display-name&gt;
  
  &lt;!-- Change to "Production" when you are ready to deploy --&gt;
  
  
  
  &lt;context-param&gt;
  &lt;param-name&gt;org.apache.myfaces.annotation.SCAN_PACKAGES&lt;/param-name&gt;
   &lt;param-value&gt;com.rout.sagar.HelloBean&lt;/param-value&gt;
  &lt;/context-param&gt;
  &lt;!-- Welcome page --&gt;
  &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;faces/hello.xhtml&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  
  &lt;!-- JSF mapping --&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;!-- Map these files with JSF --&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.faces&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>faces-config.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
      &lt;faces-config 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-facesconfig_2_0.xsd"
      version="2.0"&gt;
  
      &lt;navigation-rule&gt;
  &lt;from-view-id&gt;/hello.xhtml&lt;/from-view-id&gt;
  &lt;navigation-case&gt;
      &lt;from-outcome&gt;success&lt;/from-outcome&gt;
      &lt;to-view-id&gt;/welcome.xhtml&lt;/to-view-id&gt;
  &lt;/navigation-case&gt;
  &lt;/navigation-rule&gt;
  
  &lt;/faces-config&gt;
  </code></pre>
  
  <p>hello.xhtml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
      &lt;html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"&gt;
  
   &lt;h:head&gt;
  &lt;title&gt;JSF 2.0 Hello World&lt;/title&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
  &lt;h3&gt;JSF 2.0 Hello World Example - hello.xhtml&lt;/h3&gt;
  &lt;h:form&gt;
      &lt;h:inputText value="#{helloBean.name}"&gt;&lt;/h:inputText&gt;
      &lt;h:commandButton value="Welcome Me" action="welcome"&gt;&lt;/h:commandButton&gt;
  &lt;/h:form&gt;
  &lt;/h:body&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>Welcome.xhtml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
    &lt;html xmlns="http://www.w3.org/1999/xhtml"    
    xmlns:h="http://java.sun.com/jsf/html"&gt;
  
  
  &lt;h:head&gt;
    &lt;title&gt;JSF2.0 hello World    &lt;/title&gt;
  &lt;/h:head&gt;     
    &lt;h:body bgcolor = "red"&gt;
    &lt;h2&gt;JSF 2.0 Hello World Example welcome.xhtml&lt;/h2&gt;
    &lt;h2&gt;Welcome #{helloBean.name}&lt;/h2&gt;
    &lt;/h:body&gt;
    &lt;/html&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/bgQ7D.png" alt="Folder Structure in Eclipse"></p>