javagradleweblogic-10.x

java.lang.NoSuchMethodError: javax.servlet.http.Cookie.setHttpOnly(Z)V


I am using weblogic 10.3.6.0 application server for deploying application . after deploying one of the application which uses JDK8. at run time I got the following error.

java.lang.NoSuchMethodError: javax.servlet.http.Cookie.setHttpOnly(Z)V

contents of dependencies.gradle file are as follows

providedCompile 'javax.servlet:javax.servlet-api:3.0.1'

What would be the reason behind this error?


Solution

  • Cookie.setHttpOnly() is available since Servlet 3.0. You are deploying to WebLogic 10 which provides only Servlet 2.5.

    Note that your project is compiling against an API dependency and not the actual runtime implementation. This is correct project setup, don't change it. However you must ensure that the APIs that you selected for compilation are provided in the runtime by deploying to the correct server.