GoogleSearchBox

Custom Search

Wednesday, July 3, 2013

java.lang.NullPointerException at org.apache.jsp.index_jsp._jspInit(index_jsp.java:22) and javax.servlet.ServletException: java.lang.LinkageError

SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException at org.apache.jsp.index_jsp._jspInit(index_jsp.java:22) at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:52)
 at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:164) 
 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:723)
 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:103)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
 at java.lang.Thread.run(Thread.java:619)
Jul 3, 2013 5:27:29 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception


I googled it, found some suggestions like,
we have jsp-api.jar and servlet-api.jar placed inside the project’s WEB-INF/lib directory and That’s causing the issue. Because it should not be there as Tomcat has it already these jars in its lib.
But removing that jar from the projects   gives me this below error:


















And Sometimes, when you delete some conflicting jars (but still some conflicts remains there), then you may get below exception :

javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;

" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/index_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspApplicationContext,
have different Class objects for the type javax/el/ExpressionFactory used in the signature
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:343)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

 java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/index_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspApplicationContext, have different Class objects for the type javax/el/ExpressionFactory used in the signature


Now the root cause of this issue is jar files conflict.
Basically identical jar's located inside server's (like Tomcat's) lib directory conflict with same jars found in your deployed application's WEB-INF/lib/ directory.
Below jars in my case above were causing the issue.
1. servlet-api.jar
2. jsp-api.jar
3. el-api.jar

I had these in the BuildPath of my MyEclipse, because of class files had dependency on these.. so could not delete from there. But when I deploy the application, these jars get copied into the TOMCAT_HOME/webapps/myproject/WEB-INF/lib/

And by default my TOMCAT_HOME/lib/  directory had these jars.

Now, I can not delete the servlet-api and jsp-api jars from my MyEclipse build path, otherwise my code will have so many compile errors due to classNotFound.

So the solution I used is:
1. I deleted  servlet-api and jsp-api jars from my MyEclipse build path, and in place of these, I used javaee.jar (which had all the required class files for my project to compile).
2. Also completely deleted the el-api.jar  file too from the build path

Hope that helps for you too!!

References:
http://stackoverflow.com/questions/8487048/java-lang-linkageerror-javax-servlet-jsp-jspapplicationcontext-getexpressionfac

No comments:

Post a Comment