John Steed
John Steed

Reputation: 629

Unable To Start Tomcat 7: NoSuchMethodError getSessionCookieConfig()

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 was successfully able to launch startup.bat recently and I don't think anything has changed. Please advise, thanks.

Upvotes: 3

Views: 3514

Answers (4)

Dennis C
Dennis C

Reputation: 24747

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

Upvotes: 0

srivelayutha raja
srivelayutha raja

Reputation: 134

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 :)

Upvotes: 0

Michal
Michal

Reputation: 2423

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.

Upvotes: 0

Khalil M
Khalil M

Reputation: 1858

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

Upvotes: 1

Related Questions