Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.LinkageError: loader constraint violation: when resolving interface method javax.servlet.jsp.JspApplicationContext.getExpressionFactory() [duplicate]

I am using JSF 2.0 in Eclipse IDE. When I tried to implement JSP and Servlet, I get the following error:

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/exCrop_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
at org.apache.jsp.exCrop_jsp._jspInit(exCrop_jsp.java:31)
at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:49)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:181)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

How is this caused and how can I solve it?

like image 530
Muthu Avatar asked Nov 07 '11 05:11

Muthu


2 Answers

Your classpath is a mess.

This particular exception suggests that you've littered the webapp's /WEB-INF/lib folder with arbitrarily downloaded servletcontainer-specific libraries of a servletcontainer make/version which is incompatible with the servletcontainer where you're actually deploying the webapp to. The particular exception message suggests that your /WEB-INF/lib contains jsp-api.jar, j2ee.jar and/or javaee.jar files.

You should remove them. The servletcontainer already ships with JSP. You should never copy/move servletcontainer-specific libraries around. It would only clash with the target runtime. If you did this to workaround compilation errors in your IDE, then you should have solved it differently. Namely, you should integrate the target servletcontainer in your IDE and then associate it with the project as Targeted Runtime. This way the IDE will automatically use the servletcontainer's libraries in the compile time classpath.

See also:

  • How do I import the javax.servlet API in my Eclipse project?
like image 164
BalusC Avatar answered Oct 02 '22 17:10

BalusC


I had the same error when migrating a project from WAS6 to WAS 7. Here is the fix:

  1. Update web.xml:
    • Open Project_name\src\main\webapp\WEB-INF\web.xml
    • Add the following listener: Com.sun.faces.config.ConfigureListener
    • Build the project and deploy it to Websphere
  2. Change loader order:
    • Open Websphere application server Console
    • Go to: Applications >> Application Types >> WebSphere enterprise applications
    • Click at the project
    • Click “Class loading and update detection”
    • Choose “Classes loaded with parent loader first”
    • Click Apply
  3. Disable JSP class reloading
    • a. Go to: Applications >> Application Types >> WebSphere enterprise applications
    • Click at the project
    • Click at JSP and JSF options
    • Uncheck “JSP enable class reloading”
    • Click OK
  4. Change JSF Implementation
    • Go to: Applications >> Application Types >> WebSphere enterprise applications
    • Click at the project
    • Click at JSP and JSF options
    • Choose “MyFaces 1.2” under JSF Implementation
  5. Start the Project
like image 1
user1532638 Avatar answered Oct 05 '22 17:10

user1532638