7

I get the following exception on startup of my JSF web application:

SEVERE: Error configuring application listener of class org.apache.myfaces.webapp.StartupServletContextListener
java.lang.ClassNotFoundException: org.apache.myfaces.webapp.StartupServletContextListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3786)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

This my web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
 <display-name>J2S</display-name>
 <context-param>
  <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
  <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
  <param-value>client</param-value>
 </context-param>
 <context-param>
  <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
  <param-value>resources.application</param-value>
 </context-param>
 <context-param>
  <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
  <param-value>true</param-value>
 </context-param>
 <context-param>
  <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
  <param-value>true</param-value>
 </context-param>
 <context-param>
  <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
  <param-value>false</param-value>
 </context-param>
 <context-param>
  <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
  <param-value>true</param-value>
 </context-param>
 <listener>
  <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
 <servlet>
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <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>/faces/*</url-pattern>
 </servlet-mapping>
 <welcome-file-list>
  welcome-file>index.xhtml</welcome-file>
 </welcome-file-list>
</web-app>

How is this exception caused and how can I solve it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
jmt
  • 223
  • 1
  • 8
  • 28
  • 1
    Make sure the myfaces jar is in the lib folder of your web app. You can download the myfaces library [here](http://www.apache.org/dyn/closer.cgi/myfaces/binaries/myfaces-core-assembly-2.1.7-bin.zip). – Jeshurun May 21 '12 at 04:29

2 Answers2

12

java.lang.ClassNotFoundException: org.apache.myfaces.webapp.StartupServletContextListener

The ClassNotFoundException means that the mentioned class is missing in the application's runtime classpath. The mentioned class is part of MyFaces JSF implementation. This is thus missing in your application's runtime classpath.

In case you're using Maven, this is the proper coordinate to install MyFaces 2.3:

<dependency>
    <groupId>org.apache.myfaces.core</groupId>
    <artifactId>myfaces-impl</artifactId>
    <version><!-- Check https://myfaces.apache.org --></version>
</dependency>

Check https://myfaces.apache.org or the Maven repository for the exact version number of the latest available 2.3.x. Currently (Aug 2023) that is 2.3.10.

In case you're manually carrying around loose JAR files, then you need to download the myfaces-core-assembly-x.y.z-bin.zip file, unpack it and put the JAR files found in the /lib folder in the /WEB-INF/lib folder of your webapp project. Note that MyFaces ships with three myfaces-*.jar files, you should put either both the myfaces-api and myfaces-impl JAR files, or alone the myfaces-bundle JAR file in the /WEB-INF/lib and thus not all three.

See also:

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks the error dispear when i adding myfaces-api and myfaces-impl but i got anther error – jmt May 21 '12 at 13:45
  • SEVERE: An error occured while initializing MyFaces: javax.faces.context.ExceptionHandlerFactory java.lang.IllegalArgumentException: javax.faces.context.ExceptionHandlerFactory – jmt May 21 '12 at 14:04
  • 1
    Please press `Ask Question` button whenever you have a new question. – BalusC May 21 '12 at 14:05
  • SEVERE: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener javax.faces.FacesException: org.apache.myfaces.application.ApplicationFactoryImpl – jmt May 21 '12 at 14:05
  • 1
    Please press `Ask Question` button whenever you have a new question. You should not post new questions in comments of an already answered question. – BalusC May 21 '12 at 14:06
1

I had the same problem using Tomcat7 on Eclipse. I had all the required jar files. I discoverd that it was due to a wrong configuration of the server. Be sure, while creating a dynamic web project on Eclipse, to choose for Tomcat the JSF configuration, not the default one.

Daniela Mogini
  • 299
  • 1
  • 5
  • 17
  • 1
    I also have problem with the Tomcat. I did not quite understand what do I need to do, could you clarify with more details please? – Danijel Nov 04 '13 at 09:58