8

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?

Thor
  • 6,607
  • 13
  • 62
  • 96
Muthu
  • 269
  • 3
  • 9
  • 23

2 Answers2

12

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 3
    this can also happen if you have a "el-api.jar" jar in your lib folder – Brad Parks Feb 13 '13 at 19:29
  • @BalusC I also face this problem especially when I use maven and run the app with embedded Tomcat and target as "run". If I exclude the transitive dependency on el-api through el-impl and allow my project to use "provided" dependency on el-api, none of the JSF expressions are processing but JSP expressions are processing. – arunram Jan 10 '14 at 14:54
1

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
DisplayName
  • 3,093
  • 5
  • 35
  • 42