Monday, February 15, 2010

Solving Tomcat + JSF 2.0 Error: java.lang.LinkageError: loader constraint violation

What happens when you try running JSF 2.0 web framework on Tomcat 6? This error:

HTTP Status 500 -


type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
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:275) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 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:25) org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:52) org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:159) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.

Apache Tomcat/6.0.20

The problem is simple: Tomcat ships with an old version of el-api, the Expression Language used by JSP, JSTL, and JSF.

JSF 2.0 uses the new Java EE 6 version that is EL 2.2. Unfortunately you can't just put the new EL libraries in your WEB-INF/lib because of Tomcat's restriction.

To fix this, you don't need to change your project.. but you need to patch your Tomcat installation:
  1. Delete el-api.jar from your Tomcat's lib folder.
  2.  Get the new el-api-2.2.jar from java.net and save it as el-api.jar on the Tomcat's lib folder.
You will also need to put the new el-impl.jar on your web application's WEB-INF/lib folder.

For a Maven web project, put this in your pom.xml :
                <dependency>
                    <groupId>javax.el</groupId>
                    <artifactId>el-api</artifactId>
                    <version>2.2</version>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.glassfish.web</groupId>
                    <artifactId>el-impl</artifactId>
                    <version>2.2</version>
                    <scope>runtime</scope>
                </dependency>
You also need to use java.net's Maven repository:
<repositories>
    <repository>
        <id>java.net.m2</id>
        <url>http://download.java.net/maven/2</url>
        <snapshots>
           <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
Related Articles:

10 comments:

Lance Hankins said...

We were facing the same problem and tracked it down to the fact that we were bundling all of juel into our war file.

I switched our build to only bundle juel-impl (not juel-api), and it fixed the issue. Example maven dependency :

<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-impl</artifactId>
<version>2.1.3</version>
</dependency>

Lance Hankins said...

Actually, strike my previous comment... I did end up having to do what you outlined originally (replace the el-api.jar in tomcat/lib).

I also had to add an exclusion to the maven dependency that I referenced above, to exclude the juel-api.jar (which comes in as a transitive dependency of juel-impl.jar).

Here's the juel maven dependency now:

<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-impl</artifactId>
<version>2.1.3</version>
<exclusions>
<exclusion>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-api</artifactId>
</exclusion>
</exclusions>
</dependency>

Also... for what its worth, I'm using tomcat 6.0.28

Thanks for your post - it definitely saved me time.

Hendy Irawan said...

Thank you Lance for sharing your experience.

I'm glad you found the article useful.

Choesang said...

Thanks for sharing your solution.

Anonymous said...

Gracias brother... En verdad, no sabía porque era ese error. Hasta que encontré tu página.
Te debo la nota de mi proyecto.

Ò.Ó

mkurkcu said...

Thanks, nice blog.

coach factore outlet said...

Here we play with all sorts of influences - coach factory outlet of desired shapes tiffany jewelry to prioritize the tiffany and co manner in which I go about finding what I need," the coach factory outlet tells Ecouterre.More than 1,000 runners began the race.Not just in true religion jeans, but also in making sure you stay happy until the cheap jerseys rain every day. Hey, $350 is way less than those coach outlet. For those unfamiliar, the coach factory online (only the first coach factory count toward the rankings this year) in coach outlet online carry all their own alexander wang shoes for a daily water ration and michael kors outlet tent to sleep under;The coach factory outlet is yours, but coach factory outlet is to just be yourself and be coach outlet store online.The sleek ensemble came on show through sac burberry. Choose from brands like Bernardo, michael kors outlet and others.which saw everything he could to shake off that 'alexander wang bags' image, just got the treatment from the michael kors himself, marc by marc jacobs outlet department. the company was coach factory outlet online that it can really tell that you're turned on, so michael kors should definitely be saved for the bedroom.which has seen him take on projects from labels like michael kors outlet online, to things like designing boats.

polo outlet said...

http://www.superbagsmarket.com/
http://www.superbagsmarket.com/louis-vuitton-bags-c-1.html
http://www.superbagsmarket.com/hermes-bags-c-2.html
http://www.superbagsmarket.com/prada-bags-c-3.html
http://www.superbagsmarket.com/chanel-bags-c-4.html
http://www.superbagsmarket.com/gucci-bags-c-5.html
http://www.superbagsmarket.com/burberry-bags-c-6.html
http://www.superbagsmarket.com/celine-bags-c-7.html
http://www.superbagsmarket.com/balenciaga-bags-c-8.html
http://www.superbagsmarket.com/christian-dior-bags-c-9.html
http://www.superbagsmarket.com/chloe-bags-c-10.html
http://www.superbagsmarket.com/bvlgari-bags-c-11.html
http://www.superbagsmarket.com/bally-bags-c-12.html
http://www.superbagsmarket.com/coach-bags-c-13.html
http://www.superbagsmarket.com/michael-kors-bags-c-14.html
http://www.superbagsmarket.com/mcm-bags-c-15.html
http://www.superbagsmarket.com/fendi-bags-c-16.html
http://www.superbagsmarket.com/mulberry-bags-c-17.html
http://www.superbagsmarket.com/marc-jacobs-bags-c-18.html
http://www.superbagsmarket.com/miu-miu-bags-c-19.html
http://www.superbagsmarket.com/ysl-bags-c-20.html
http://www.superbagsmarket.com/tory-burch-bags-c-21.html
http://www.superbagsmarket.com/givenchy-bags-c-22.html
http://www.superbagsmarket.com/ferragamo-bags-c-23.html
http://www.superbagsmarket.com/lancel-bags-c-24.html
http://www.superbagsmarket.com/loewe-bags-c-25.html
http://www.superbagsmarket.com/tods-bags-c-26.html
http://www.superbagsmarket.com/paul-smith-bags-c-27.html
http://www.superbagsmarket.com/dg-bags-c-28.html
http://www.superbagsmarket.com/alexander-wang-bags-c-29.html
http://www.superbagsmarket.com/bottega-veneta-bags-c-30.html
http://www.superbagsmarket.com/specials.html
http://www.guccishoesuk-2014.com/
http://www.burbagssale2014.com/
http://www.polo-ralphlaurenonline.com/
http://www.thebeatsbydre.net/

Eric Simmons said...

Great and Useful Article.

Online Java Course

Java Online Training

Java Course Online

J2EE training

online J2EE training

Best Recommended books for Spring framework

Java Interview Questions








Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

Java Course in Chennai

Getit said...

This is totally great. Download Zapya for PC, Zapya free download, Zapya download, Zapya apk to share files and folders

Post a Comment

 
Copyright 2009 Spring vs Java EE Web Dev. Powered by Blogger Blogger Templates create by Deluxe Templates. WP by Masterplan