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

3

9

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"]
Triptych answered 9/1, 2013 at 16:58 Comment(4)
How's WTP configured (assuming you use WTP)? Are your classes properly deployed to Tomcat?Platform
Yes I'm using WTP and Jersey. All the WTP settings should be default. The src directory containing the package deploys to WEB-INF/classes and /WebContent deploys to / (as the default) .Triptych
Edit: I've added the full console log to the postTriptych
@MarcelStör- I solved this problem a bit ago and everything is now working. But you are right the classes weren't being deploed by Eclipse . If you could post that as an answer I will accept it!Triptych
N
13

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

Nikko answered 24/2, 2013 at 19:24 Comment(3)
This aspect of Eclipse can be maddening.Fob
@Fob - it's just one of many for me. The m2e, WTP and SVN plugins are all sad stories. Used it for 10+ years but I'm a happy IntelliJ user now.Platform
@MarcelStör If IntelliJ is as inconvenient and buggy as Android Studio (which is based on IntelliJ) then I don't understand how people can work with this and even pay for this.Es
B
1

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.

Beachhead answered 25/7, 2020 at 15:12 Comment(0)
B
0

result in having deleted library source or moved one in build path. make sure you dont have any missed library in build path > Libraries.

clean project and run tomcat again.this will help.

Blanks answered 18/7, 2015 at 21:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.