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

老子叫甜甜 提交于 2019-12-17 02:23:08

问题


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?


回答1:


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?



回答2:


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>



回答3:


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




回答4:


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>



回答5:


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



回答6:


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.



来源:https://stackoverflow.com/questions/8487048/java-lang-linkageerror-javax-servlet-jsp-jspapplicationcontext-getexpressionfac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!