Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Servlet.service() throws ClassCastException

I have a java web application. I have set up this new project and getting the following exception when I run a jsp,

Oct 10, 2012 3:01:49 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.ClassCastException: org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.apache.AnnotationProcessor
    at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:151)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:340)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)
Oct 10, 2012 3:01:57 AM org.apache.catalina.loader.WebappClassLoader modified
INFO:     Additional JARs have been added : 'activation-1.1.jar'
Oct 10, 2012 3:01:57 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading this Context has started
Oct 10, 2012 3:01:57 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/AutoUpgrade] registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Oct 10, 2012 3:01:57 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/AutoUpgrade] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.

I have tried clean and building the project many times, getting the latest service-api.jar, my lib is very extensive and I cannot figure out whether there is any inconsistencies between any jar that is causing this error. I am running the project on Apache Tomcat 6 on jdk 1.6 (my project needs to run on 1.6). I have tried googling this exception, but didnt get any post relevant to my problem. The relevant questions on stackoverflow talk about NullPointerException.

I think the problem must be with my library, but I can not point to root cause.

Thanks

like image 368
Rishabh Avatar asked Oct 10 '12 07:10

Rishabh


1 Answers

This can happen when you have Tomcat-specific JAR files in your webapp's /WEB-INF/lib. This is not right. You should remove all servletcontainer-specific JAR files from there. They do not belong there at all. They are supposed to be already provided by the servletcontainer itself. The /WEB-INF/lib should only contain libraries specific to the webapp itself which are not provided by the servletcontainer.

If you have placed them there as a result of an unthoughtful attempt to fix compilation errors, then please carefully read this answer how to solve it the right way: How do I import the javax.servlet API in my Eclipse project?

like image 93
BalusC Avatar answered Nov 10 '22 13:11

BalusC