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

懵懂的女人 提交于 2019-12-21 09:21:23

问题


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?


回答1:


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?



回答2:


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


来源:https://stackoverflow.com/questions/8033065/java-lang-linkageerror-loader-constraint-violation-when-resolving-interface-me

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