java.lang.LinkageError: javax.servlet.jsp.JspApplicationContext.getExpressionFactory
Asked Answered
A

6

29

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?

Alvaroalveolar answered 13/12, 2011 at 9:42 Comment(0)
A
58

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:

Aer answered 13/12, 2011 at 12:4 Comment(1)
If Appserver exposes few classes from a jar how do we resolve that issue? Should we include the missing classes in the lib directory?Rules
A
16

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>
Apologue answered 8/2, 2013 at 15:10 Comment(0)
K
3

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>
Kuhn answered 10/6, 2014 at 18:4 Comment(0)
C
2

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

Care answered 13/12, 2011 at 10:57 Comment(1)
The page you are looking for has moved. start a new java class search hereAnguiano
H
0

This is weird ERROR i got ever

After reserach i found this Causes and solution

I am using Spring so in my @spring libraries i already have the jar like

Servlet-api.jar or javax-servlet-api.jar jsp-api.jar or javax-servlet-jsp.jar

But this is not compatible wid my TOMCAT server So simply i remove these two jars from my built path and deployment assembly Now i goto my "E:\Locker\Software\apache-tomcat-6.0.44\lib" where are my Tomcat server and add these two jars to my project

servlet-api.jar
jsp-api.jar
Haldan answered 1/7, 2015 at 8:6 Comment(0)
B
0

In my case, I had the tomcat dependency as well as the tomcat plugin mentioned in the POM. Removed the dependency leaving just the plugin in there and it worked.

Brunet answered 11/8, 2019 at 8:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.