Sunday, July 1, 2012

Tomcat error on startup: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()

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


Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig;
at org.apache.catalina.deploy.WebXml.configureContext(WebXml.java:1309)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1310)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:855)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:345)
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:5161)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)




The offending method is:

SessionCookieConfig scc = context.getServletContext().getSessionCookieConfig();

and context is passed as "configureContext(Context context)"

and Context is "org.apache.catalina.Context"


I found out a different version of the javax.servlet package in wlfullclient.jar



in the servlet-api.jar in Tomcat in the Interface javax.servlet.ServletContext you can find the method:

public abstract SessionCookieConfig getSessionCookieConfig();


The error is triggered in org.apache.catalina.deploy.WebXml class, which is in catalina.jar.




I have tried this and it doesn work:

copy to tomcat/lib directory these files
javax.persistence-2.0.0.jar http://mvnrepository.com/artifact/org.eclipse.persistence/javax.persistence
persistence-api-1.0.2.jar http://mvnrepository.com/artifact/javax.persistence/persistence-api


The only thing which works is detecting the extra jar introducing the wrong version of the javax.servlet package and get it out of the way.

No comments: