title: Listener class not executing while server startup || tomcat || eclipse
body: <p>I am working on eclipse gallileo,struts and tomcat.
  following is my web.xml file</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;streetmall&lt;/display-name&gt;
   &lt;context-param&gt;
    &lt;param-name&gt;imagePath&lt;/param-name&gt;
    &lt;param-value&gt;D:\\OrderID_images&lt;/param-value&gt;
   &lt;/context-param&gt;
   &lt;listener&gt;
    &lt;listener-class&gt;jaha.Customer.util.ApplicationScopeInit&lt;/listener-class&gt;
   &lt;/listener&gt;
   &lt;servlet&gt;
    &lt;servlet-name&gt;action&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt;
    &lt;init-param&gt;
     &lt;param-name&gt;config&lt;/param-name&gt;
     &lt;param-value&gt;/WEB-INF/struts-config.xml&lt;/param-value&gt;
    &lt;/init-param&gt;
    &lt;init-param&gt;
     &lt;param-name&gt;debug&lt;/param-name&gt;
     &lt;param-value&gt;3&lt;/param-value&gt;
    &lt;/init-param&gt;
    &lt;init-param&gt;
     &lt;param-name&gt;detail&lt;/param-name&gt;
     &lt;param-value&gt;3&lt;/param-value&gt;
    &lt;/init-param&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
   &lt;/servlet&gt;
   &lt;servlet&gt;
    &lt;servlet-name&gt;action_tmp&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt;
    &lt;init-param&gt;
     &lt;param-name&gt;config&lt;/param-name&gt;
     &lt;param-value&gt;/WEB-INF/struts-config.xml&lt;/param-value&gt;
    &lt;/init-param&gt;
    &lt;init-param&gt;
     &lt;param-name&gt;debug&lt;/param-name&gt;
     &lt;param-value&gt;3&lt;/param-value&gt;
    &lt;/init-param&gt;
    &lt;init-param&gt;
     &lt;param-name&gt;detail&lt;/param-name&gt;
     &lt;param-value&gt;3&lt;/param-value&gt;
    &lt;/init-param&gt;
    &lt;load-on-startup&gt;0&lt;/load-on-startup&gt;
   &lt;/servlet&gt;
   &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;action&lt;/servlet-name&gt;
    &lt;url-pattern&gt;*.do&lt;/url-pattern&gt;
   &lt;/servlet-mapping&gt;
   &lt;welcome-file-list&gt;
    &lt;welcome-file&gt;welcome.jsp&lt;/welcome-file&gt;
   &lt;/welcome-file-list&gt;
  
   &lt;login-config&gt;
    &lt;auth-method&gt;BASIC&lt;/auth-method&gt;
   &lt;/login-config&gt;
  
    &lt;description&gt;MySQL Test App&lt;/description&gt;
    &lt;resource-ref&gt;
        &lt;description&gt;DB Connection&lt;/description&gt;
        &lt;res-ref-name&gt;jdbc/TestDB&lt;/res-ref-name&gt;
        &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
        &lt;res-auth&gt;Container&lt;/res-auth&gt;
    &lt;/resource-ref&gt;&lt;/web-app&gt;
  </code></pre>
  
  <p>My Problem is when I am startig my tomcat server, my lister class is not getting executed. even I have putted some System.out.println(). those messages are also not coming on console.. please help me how to get rid off this.</p>
  
  <p><strong>earlier i was getting class not found exception. but then  I created new project and deploy it. now I am in this problem</strong>
  Thanks</p>
  
  <pre><code>public class ApplicationScopeInit implements ServletContextListener 
  {
  
      public void contextInitialized(ServletContextEvent event) 
      {
          try
          {
              ClassLoader loader = Thread.currentThread().getContextClassLoader();
  
              System.out.println("Use context classloader to read states.properties");
              InputStream iStream = loader.getResourceAsStream("jaha/Customer/states.properties");
              Properties props = new Properties();
              System.out.println("Load the stream into the properties object directly");
              props.load(iStream);
  
              //Look up by key and load them into a ArrayList as NameValuePair collection
              Enumeration keyEnum = props.propertyNames();
              // Use a Sorted Set to hold the state names and values
              // Define an anonymous inner class to provide
              // the comparison algorithm to the TreeSet
              @SuppressWarnings("unchecked")
              Set stateSet = new TreeSet(
                      new Comparator() 
                      {
                          public int compare(Object a, Object b)
                          {
                              LabelValueBean nvpA = (LabelValueBean) a;
                              LabelValueBean nvpB = (LabelValueBean) b;
  
                              String valA = nvpA.getLabel();
                              String valB = nvpB.getLabel();
                              return valA.compareTo(valB);
                          }
                      }
              );
  
              LabelValueBean nvp = null;
              String keyName = null;
              String label = null;
              while (keyEnum.hasMoreElements())
              {
                  keyName = (String) keyEnum.nextElement();
                  label = props.getProperty(keyName);
                  nvp = new LabelValueBean(label, keyName);
                  stateSet.add(nvp);
              }
  
              System.out.println("Get ServletContext and set the properties as a application scope object");
              ServletContext context = event.getServletContext();
              context.setAttribute("STRUTS_EXAMPLE_STATES", stateSet);
  
  
              //Load Carriers - FedEx, UPS etc..
              List carrierList = new ArrayList();
              carrierList.add(new LabelValueBean("UPS", "UPS"));
              carrierList.add(new LabelValueBean("USPS", "USP"));
              carrierList.add(new LabelValueBean("FedEx", "FDX"));
  
              context.setAttribute("STRUTS_EXAMPLE_CARRIERS",carrierList);
              //.setAttribute("STRUTS_EXAMPLE_CARRIERS",carrierList);
          }
          catch (IOException ioe)
          {
              ioe.printStackTrace();      
          }
          try{
              System.out.println("Populating category on server startup");
              HashMap&lt;String, ArrayList&lt;CategorydetailObject&gt;&gt;  hm= CategoryManager.PopulateCategory();
              ServletContext context = event.getServletContext();
  
              context.setAttribute("PRODUCTS", hm);
  
  
  
          }
          catch(Exception e)
          {
              System.out.println("$$$$$$$$$$$$$$$$$$$$$ PROBLEM IN INITIALIZATION ALL PARAMETERS");
  
          }
      }
  
      public void contextDestroyed(ServletContextEvent event) 
      {
          event.getServletContext().removeAttribute("STRUTS_EXAMPLE_STATES");
          event.getServletContext().removeAttribute("STRUTS_EXAMPLE_CARRIERS");
          event.getServletContext().removeAttribute("PRODUCTS");
  
      }
  
  }
  </code></pre>