5

after upgrading to latest version of eclipse Helios 3.6, M2E 1.0 , WTP 3.2.5 and trying to run my maven project which uses JSF 2.1.3 and Spring 3 on tomcat 7, i am getting the following exception:

java.lang.ClassNotFoundException: javax.servlet.jsp.el.ImplicitObjectELResolver$ImplicitObjects$4
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
    at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2006)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1969)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1858)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1826)
    at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1812)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1306)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:896)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:322)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5103)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:621)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)

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:693)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:243)
    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(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Dec 17, 2011 4:56:04 PM 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:292)
    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(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
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:693)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:243)
    ... 8 more

following is my configuration for maven:

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
       </dependency>


        <dependency>
         <groupId>com.sun.faces</groupId>
         <artifactId>jsf-api</artifactId>
         <version>2.1.3</version>
        </dependency>

        <dependency>
         <groupId>com.sun.faces</groupId>
         <artifactId>jsf-impl</artifactId>
         <version>2.1.3</version>
        </dependency>

        <dependency>
          <groupId>jstl</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
        </dependency>

am i missing a jar file, or using an incompatible version of a jar ?

please advise, thanks.

UPDATE: what i get so far is that i get the application to run fine by removing the following dependencies from pom file:

<dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.2.1</version>
           <scope>provided</scope>
          </dependency>

          <dependency>
           <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
           <version>2.2.2</version>
           <scope>provided</scope>
          </dependency>

i think that they were conflicting with the jars provided by the container.

WHAT I NEED TO KNOW:

1- Do i have to add the dependencies: javax.servlet.jsp-api , javax.el-api to my pom file as provided or i don't need to add them at all ?

2- If i have to add those two dependencies, then how should i add them properly in a way that they will not conflict with tomcat jars, meaning what version, and should i mark the dependency as provided or not ?

and the important question if i have to add them, why i have to do that, what is the importance of adding them since they are provided by the container, what i understand so far, is that i need to add the javax.servlet-api dependency and mark it as provided since i am using servlets in some classes.

Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498
  • 4
    I'm no Maven guy, so I have no idea how to fix this, but I can at least tell that the exception indicates that you've multiple EL API JAR files in the final webapp's runtime classpath (conflicting class is of `javax.el` package). If you're certain that Maven is doing its job right, then you need to verify if you haven't *manually* placed anything in `/WEB-INF/lib`, `Tomcat/lib`, `JRE/lib`, `JRE/lib/ext` and any other path which is covered by webapp's runtime classpath. Tomcat 7 ships by itself already with the right EL 2.2 API/impl, so you should not need to supply it yourselves (or by Maven). – BalusC Dec 17 '11 at 16:13
  • @BalusC so you mean that i should remove el dependency which is marked as provided, and only include the jsp-api and servlet-api as provided ? – Mahmoud Saleh Dec 17 '11 at 16:36
  • As said, I'm no Maven guy. I have no idea. You need to verify if the Maven-built WAR is all right and if you don't have manually cluttered the aforementioned library paths with duplicated EL API JAR file(s). – BalusC Dec 17 '11 at 16:38
  • 2
    I would also recommend upgrading to Eclipse 3.7.1 (Indigo), as that is the latest stable release of Eclipse. – Alexander Pogrebnyak Dec 17 '11 at 18:18
  • @Alexander Pogrebnyak , i even tried to remove all dependencies from .m2 and make full maven clean and install, and still getting same error, and hints for the error cause ? – Mahmoud Saleh Dec 20 '11 at 21:13
  • Try to set for deps exactly matching the ones in tomcat 7. Try system. – Vadzim Dec 22 '11 at 11:59
  • @Vadzim, you mean to add `javax.servlet.jsp-api` , `javax.el-api` as scope system ? what does scope system mean, and how to know the exact versions for each jar in tomcat 7 ? – Mahmoud Saleh Dec 22 '11 at 13:05
  • http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope. system just to try but provided fits better. http://stackoverflow.com/questions/5834794/how-to-check-the-version-of-jar-file/ – Vadzim Dec 22 '11 at 16:23
  • See also http://stackoverflow.com/questions/1031695/how-to-exclude-jars-generated-by-maven-war-plugin. But this still gives no answer why provided deps got in war in your case. – Vadzim Dec 22 '11 at 17:05

2 Answers2

2

You should add these dependencies only if you require them in your code meaning that they are required to compile your code. If you don't use JSP or EL classes in your code, you can remove the dependencies. So you can test if you need the dependencies by just removing them. If your code still compiles, you don't need them. :)

If you need them, you should definitely add them as provided dependencies because the classes are provided by Tomcat during runtime. Just make sure that the versions of the dependencies match the versions provided by Tomcat. Then you won't have any problems. Provided dependencies are just used to compile your code but they are not packaged into the resulting WAR file, which is OK, because Tomcat provides them.

Jesse Webb
  • 43,135
  • 27
  • 106
  • 143
chkal
  • 5,598
  • 21
  • 26
1

I had a similar problem: I was able to run a project in one computer, but in another one, I was obtaining the ClassNotFoundException described in the question.

The only difference between the 2 environments was the version of the tomcat server: 7.0.26 in the working computer and 7.0.16 in the other one. I installed the same version in both computers (7.0.26) and it solved the issue.

I hope this answer could be useful to someone.

eternay
  • 3,754
  • 2
  • 29
  • 27