Monday, January 12, 2009

java.lang.NoClassDefFoundError: javax/el/ValueExpression Fix: Exclude servlet-api from Portlet Dependencies and Include as Provided

Was getting the error when running a portlet:
"java.lang.NoClassDefFoundError: javax/el/ValueExpression"
(see also: http://forum.springframework.org/showthread.php?t=63028) Since the project was using Maven 2, I ran the following command:
mvn dependency:tree
then I found out that one of the dependencies (cas:casclient:2.1.1) was including servlet-api (jar) which should not be included in portlets, but they should be "provided" scope since the jar should be available via Tomcat's common/lib. I added the exclusion to that dependency in pom.xml:
        <dependency>
        ...
            <exclusions>
                <exclusion>
                    <groupId>javax.servlet</groupId>
                    <artifactId>servlet-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
and because it happened to be needed for the code to compile, add it as a provided dependency:
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>
Note: it is probably a good idea to use whatever servlet-api version works with your webapp server/platform. For example: (from http://tomcat.apache.org/)
Servlet/JSP Spec   Apache Tomcat version
2.5/2.1            6.0.18
2.4/2.0            5.5.27
2.3/1.2            4.1.39
2.2/1.1            3.3.2
Note that certain versions of Maven 2 have a bug (referenced I think in (MNG-2205 and MNG-3890) related to provided scope. If this is the case for you, you could try updating Maven 2 to a newer version, and at time of writing, that means having to build a new version of Maven 2. The issue I ended up with on top of this is that I wasn't removing the webapp that I was using uPortal deployPortletApp with locally and then zipping back up for actual deployment. I fixed that script, plutofy.sh, so if you use it, please go back and get the newer version.

No comments: