8
INFO: Deploying web application archive test-1.0-SNAPSHOT.war
20-Sep-2011 12:08:42 org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\software\apache-tomcat-7.0.21\webapps\test-1.0-SNAPSHOT\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
20-Sep-2011 12:08:42 com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.1.0 (SNAPSHOT 20100817) for context '/test-1.0-SNAPSHOT'
20-Sep-2011 12:08:42 com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.
20-Sep-2011 12:08:43 com.sun.faces.config.ConfigureListener contextInitialized
SEVERE: Critical error during deployment: 
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/catalina/loader/WebappClassLoader) of the current class, com/sun/faces/config/ConfigureListener, 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 com.sun.faces.config.ConfigureListener.registerELResolverAndListenerWithJsp(ConfigureListener.java:684)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:240)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
20-Sep-2011 12:08:43 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener
java.lang.RuntimeException: 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/catalina/loader/WebappClassLoader) of the current class, com/sun/faces/config/ConfigureListener, 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 com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:290)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: 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/catalina/loader/WebappClassLoader) of the current class, com/sun/faces/config/ConfigureListener, 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 com.sun.faces.config.ConfigureListener.registerELResolverAndListenerWithJsp(ConfigureListener.java:684)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:240)
    ... 8 more
20-Sep-2011 12:08:43 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
20-Sep-2011 12:08:43 org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/test-1.0-SNAPSHOT] startup failed due to previous errors

I am trying to run mkyong hello world JSF2 example http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/

POM.xml is

<dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.0-b03</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.0-b03</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
    </dependency>

    <dependency>
        <groupId>com.sun.el</groupId>
        <artifactId>el-ri</artifactId>
        <version>1.0</version>
        <scope>provided</scope>
    </dependency>

This thread loader constraint violation describes same issue in tomcat 6 but it is not help to solve my issue.

Community
  • 1
  • 1
TechFind
  • 3,696
  • 18
  • 47
  • 62
  • I'll share this answer from Fred Bricon that solved the same problem I had: http://stackoverflow.com/a/10101843/1712925 (In short, probably m2e-wtp plugin should be installed or scope-provided configs won't work with WTP Tomcat) – Uros Oct 01 '12 at 21:05

4 Answers4

9

I don't do Maven, but given the answer of Pascal Thivent in your linked question, it seems that you need to mark a Maven dependency as provided whenever the target runtime already ships with it out the box.

Tomcat as being a simple servletcontainer ships with JSP, Servlet and EL out the box (only not with JSF and JSTL). The exception message which you got indicates duplication of the JSP API in the classpath. I suggest to set the JSP and Servlet entries in your pom.xml to provided as well.

Further, you will get a second major problem after you fix the problem as stated in the question, Mojarra 2.1.0 does not work in Tomcat. Upgrade to Mojarra 2.1.1 or newer (it's currently at 2.1.3). See also the Mojarra download page for pom snippets.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 2
    i have made servlet-api, jsp-api and el-ri as Provided. ie provided. But no use same error occurs. – TechFind Sep 20 '11 at 12:03
  • 1
    Then it indicates that you still have the JARs in `/WEB-INF/lib` folder of the deployed webapp. Doublecheck and cleanup. – BalusC Sep 20 '11 at 12:08
  • suppose I am deploying in another Application server where these jars not provided, then it will be a problem isn't it? how to solve in that case? – TechFind Sep 20 '11 at 12:38
  • Every JSP/Servlet container ships with JSP/Servlet/EL libraries already (how else would they be able to run JSP/Servlet webapps do you think?). Only JSF and JSTL (and many others) are already provided by more fledged appservers such as Glassfish, JBoss AS, etc (Tomcat is basically a barebones servletcontainer). If you ever need to deploy to a real appserver, you'd need to change your pom to mark JSF/JSTL as provided. – BalusC Sep 20 '11 at 12:41
  • ok, but when i tried to run Tomcat 7 in Eclipse-indigo with WTP, still servlet-api, jsp-api and el-ri.jar file exist in this location(metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\test\WEB-INF\lib) which causes server loading error. – TechFind Sep 21 '11 at 12:03
  • i have done clean, publish by right click of Tomcat server. But under plugin directory still i am able to see servlet, el and jsp jars. How can i clean plugin directory? – TechFind Sep 21 '11 at 15:24
  • Maven has to do it. I can't provide further detail as I don't use Maven. – BalusC Sep 21 '11 at 15:39
  • I added `provided` scope to Maven dependency & it works. Thanks. Upvote – OO7 Apr 03 '15 at 11:23
0

commenting out

<dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.1</version>
</dependency> 

did the trick for me. It seems since jsp was already provided adding the dependency was unnecessary and producing the error

Marquis Blount
  • 7,585
  • 8
  • 43
  • 67
0

This answer is a supplementation of BalusC's answer. hope this will help.

Use Tomcat 7 as the container. You must consider the default Shared Library Files.

For me, there are such files in directory $TOMCATHOME/lib:

  1. annotations-api.jar
  2. catalina-ant.jar
  3. catalina-ha.jar
  4. ...
  5. jsp-api.jar
  6. servlet-api.jar
  7. ...

That's why you have to mark servlet-api, jsp-api and el-ri as provided, or even exclude the JARs.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Teifi
  • 713
  • 2
  • 12
  • 20
-2

Try to put your jar file in your project BuildPath->Configure BuildPath->Libraries->Add External Jar..