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?
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.
You have two options for adding to your projects libraries, such as jsp-api.jar
, el-api.jar
, servlet-api.jar
, etc:
Java Build Path
;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>
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>
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.:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With