Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.LinkageError: javax.servlet.jsp.JspApplicationContext.getExpressionFactory

When I try to run my webapp on Tomcat 7, I got the following exception:

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
org.apache.jsp.index_jsp._jspInit(index_jsp.java:31)
org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:49)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:180)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

It seems that there's a conflict between two .jar librairies, but I don't know which they are. How can I figure them out and solve it?

like image 599
Br3x Avatar asked Dec 13 '11 09:12

Br3x


4 Answers

That will happen when you include server-specific libraries of a different server make/version in the /WEB-INF/lib of your web application, such as jsp-api.jar, el-api.jar, servlet-api.jar, etc. You need to remove them all. The /WEB-INF/lib should not contain any server-specific libraries. They belongs in the specific server itself (Tomcat has them in its /lib folder already).

This is by the way a pretty common beginner's mistake whenever they encounter compilation errors on the JSP/Servlet API in their IDE project. This should have been solved differently, namely by integrating the server in the IDE and adding the server as "Target runtime" to the project.

See also:

  • How do I import the javax.servlet API in my Eclipse project?
like image 189
BalusC Avatar answered Nov 20 '22 06:11

BalusC


You have two options for adding to your projects libraries, such as jsp-api.jar, el-api.jar, servlet-api.jar, etc:

  1. Add these libraries as external jars in your Java Build Path;
  2. Add them as maven dependencies, setting the provided scope for each of them, for example:
<dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.1</version>
    <scope>provided</scope>
</dependency>
like image 16
vadim Avatar answered Nov 20 '22 04:11

vadim


I was stuck with this error for a very long time and this thread saved quite bit of my time. Adding some research I did before resolving this issue. Yes we need to remove libraries like jsp-api.jar, el-api.jar, servlet-api.jar from /WEB-INF/lib folder. But how?

In my case I am using Apache Ivy as a dependency manger and used Spring MVC. It downloads all dependencies along with the libraries mentioned above. At runtime these conflicts with the APIs provided by Tomcat libraries. Simple solution would be to exclude these jars from dependencies or create configurations and include these libraries in compile time configuration only. What worked for me quickly is excluding these libraries.

    <dependency org="org.springframework" name="spring-webmvc"
        rev="4.0.4.RELEASE">
        <exclude org="javax.servlet" name="javax.servlet-api" />
        <exclude org="javax.servlet.jsp" name="jsp-api" />
        <exclude org="javax.el" name="javax.el-api" />
    </dependency>
like image 3
Aniket Thakur Avatar answered Nov 20 '22 05:11

Aniket Thakur


Check this page

http://www.jarfinder.com/index.php/java/info/org.apache.jasper.runtime.HttpJspBase

Find which are the jars you have used in this. Removeone if you find two.:)

like image 2
Kris Avatar answered Nov 20 '22 05:11

Kris