Unable To Start Tomcat 7: NoSuchMethodError getSessionCookieConfig()

3.4k views Asked by At

I have used Tomcat about two months ago and it started OK. Now I'm getting this message:

SEVERE: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/docs]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1120)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1678)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig;
    at org.apache.catalina.deploy.WebXml.configureContext(WebXml.java:1374)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1351)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 10 more

Please note the following behavior:

  • I get this error when I attempt to run catalina.bat. If I run Tomcat via Eclipse, it launches successfully

  • I downloaded the same version of Tomcat again and run it immediately without adding any webapps (to simply load the default Tomcat localhost page) but again I get this error.

  • As per previous similar questions, I replaced servlet-api.jar in apache's lib folder, but it has made no difference

I was successfully able to launch startup.bat recently and I don't think anything has changed. Please advise, thanks.

4

There are 4 answers

4
Khalil M On
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig;

getSessionCookieConfig() is introduced since version 3, so this error is thrown because there is abosolutely an older version in your classpath.

I would suggest to resolve your problem:

1-make sure you update the servlet version to 3

2-try to find any dependecy of servlet-api and get rid of it

3-check your classpath for any potential dependency

4-make that /WEB-INF/lib of course doesn't contain servlet-api

5-make sure that web.xml suits the standards of servlet 3

0
Michal On

The tomcat is definitely trying to deploy an application containing the wrong version of javax.servlet.ServletContext.

When starting with new fresh tomcat installation please make sure there is no aplication deployed, i.e. that $CATALINA_BASE/webapps is empty and that no $CATALINA_BASE/conf/[enginename]/[hostname]/[webappname].xml exists. Please make also sure that CATALINA_BASE and CATALINA_HOME environment variables are showing to the right installation. Make sure $CATALINA_HOME/conf/catalina.properties is the file from fresh installation. When using the fresh installation together with eclipse then also delete the tmp and work folders afterwards. This is enough to make tomcat start cleanly.

Now to get your tomcat starting with your application again. Please make sure the application does not bring the obsolete version of javax.servlet.ServletContext with it. Most obviously that would be caused by the application bringing own servlet-api.jar but it might also be caused by some other jar containing that class. If you do not find servlet-api in your application then please unpack all jars from your application and look in the javax.servlet folder.

0
Dennis C On

One possible is that you have the wrong JAR in "lib/ext" in your JAVA_HOME.

0
srivelayutha raja On

Check your java lib / all the file system for 'servlet.jar' refer the below thread...

Java Servlet deployment on tomcat eclipse - Need reference

given the answer in that thread

Removed servlet.jar in the classpath. I just searched for servlet.jar and removed everything except from lib folder. Which helped me to get rid off this error :)