Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServletContextListener SEVERE: Error configuring application listener of class marktest.Config

My Java servlet appears to be complaining that it can't find a file which is included in the package (marktest). Im using Eclipse (Indigo) to develop and Tomcat7.

Here is the error:

SEVERE: Error configuring application listener of class marktest.Config
java.lang.ClassNotFoundException: marktest.Config
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)

Here is Config.java which contains the class implementing ServletContextListener which it says it can't find in the error:

package marktest;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


public class Config implements ServletContextListener 
{

    private ExecutorService executor;

    @Override
    public void contextInitialized(ServletContextEvent event) 
    {
        System.out.println("########################## ServletContextListener started ###############################");

    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
    }

}

and here is 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>de.vogella.jersey.first</display-name>
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>marktest</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>

    <listener>
        <listener-class>marktest.Config</listener-class>
    </listener>

</web-app> 

I'm rather stumped even after much Googling. Thanks in advance for your help.

Mark

---- Edit ----

Below is the full console log

10-Jan-2013 15:45:18 org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:nlpServer' did not find a matching property.
10-Jan-2013 15:45:18 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
10-Jan-2013 15:45:18 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 661 ms
10-Jan-2013 15:45:18 org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
10-Jan-2013 15:45:18 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.21
########################## ServletContextListener started ###############################
10-Jan-2013 15:45:19 org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [1,052] milliseconds.
10-Jan-2013 15:45:19 com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
  marktest
10-Jan-2013 15:45:19 com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class marktest.hello
10-Jan-2013 15:45:19 com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
10-Jan-2013 15:45:19 com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.16 11/28/2012 02:09 PM'
10-Jan-2013 15:45:20 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class marktest.Config
java.lang.ClassNotFoundException: marktest.Config
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)
10-Jan-2013 15:45:20 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
10-Jan-2013 15:45:20 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
10-Jan-2013 15:45:20 org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [] startup failed due to previous errors
10-Jan-2013 15:45:20 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
10-Jan-2013 15:45:20 org.apache.catalina.startup.Catalina start
INFO: Server startup in 2538 ms
10-Jan-2013 15:45:24 org.apache.catalina.core.StandardServer await
INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
10-Jan-2013 15:45:24 org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8080"]
10-Jan-2013 15:45:25 org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
10-Jan-2013 15:45:25 org.apache.catalina.util.LifecycleBase stop
INFO: The stop() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]] after stop() had already been called. The second call will be ignored.
10-Jan-2013 15:45:25 org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-8080"]
10-Jan-2013 15:45:25 org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-8080"]
like image 299
Mark Avatar asked Jan 09 '13 16:01

Mark


2 Answers

Looks to me as if your classes weren't properly deployed to Tomcat by WTP (clean/publish again).

like image 108
Marcel Stör Avatar answered Nov 17 '22 20:11

Marcel Stör


Even I got the same ClassNotFoundException earlier when listener-class entry configured in tomcat server web.xml as highlighted in given snapshot - Eclipse Project Configuration Snapshot

After getting this error, same entry I have replaced from tomcat config Web.xml to {Project_Path}/WebContent/WEB-INF/web.xml.

Post that Error is resolved at tomcat server startup.

like image 39
jaydeep Avatar answered Nov 17 '22 20:11

jaydeep