Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.ClassNotFoundException: org.apache.jsp.index_jsp

Tags:

jsp

maven

I have an old struts 1 app that has always been built using Ant, which I'm converting to use Maven instead. The structure of my app is modular, with dependency management in the containing module. The containing module's dep mgmt section contains:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        ...
    </dependencies>
</dependencyManagement>

When I build the war (I run the package Maven job from the containing module) and run a Tomcat configuration with that war from intelliJ, I see the following in my browser:

org.apache.jasper.JasperException: org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:161)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:340)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause
org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:630)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:149)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:340)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause
java.lang.ClassNotFoundException: org.apache.jsp.index_jsp
java.net.URLClassLoader$1.run(URLClassLoader.java:202)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:190)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:134)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:628)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:149)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:340)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Everything I can find from searching on this suggests the cause is a version conflict in javax.servlet jars, but there is nothing in my WEB-INF/lib directory at all. I have tried using scope of provided, compile, and even install/pom, but those don't do anything helpful.

There is nothing additional in the tomcat logs.

I confirmed that the jsps are being compiled. I am using jspc-maven-plugin.

In my sub-module's (not the containing one's) pom.xml, I have:

<build>
    <!-- default goal to run if somebody doesn't pick one (rarely matters) -->
    <defaultGoal>install</defaultGoal>

    <!-- resources and filtering - also see configuration under maven-war-plugin below -->
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <filters>
        <filter>src/main/resources/${env}.properties</filter>
        <filter>src/main/resources/${env}.tokens</filter>
    </filters>

    <plugins>
        <!-- begin - precompiling jsps -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jspc-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>jspc</id>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                    <configuration>
                        <warSourceDirectory>${basedir}/src/main/webroot</warSourceDirectory>
                        <inputWebXml>${basedir}/src/main/webroot/WEB-INF/web.xml</inputWebXml>
                        <!--<workingDirectory>${basedir}/src/main/webroot</workingDirectory>-->
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <!-- end - precompiling jsps -->

        <!-- used to build warfiles -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.0</version>
            <configuration>
                <webResources>
                    <resource>
                        <directory>${pom.basedir}/src/main/webroot</directory>
                        <filtering>true</filtering>
                        <!--<targetPath>WEB-INF</targetPath>-->
                    </resource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
</build>

I can see in the maven build output that the jsps are being compiled. But I still get the JasperException.

like image 958
barclay Avatar asked Nov 13 '13 19:11

barclay


2 Answers

It's been a while since I posted this, but I thought I would show how I figured it out (as best as I recall now).

I did a Maven dependency tree to find dependency conflicts, and I removed all conflicts with exclusions in dependencies, e.g.:

<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging-api</artifactId>
    <version>1.1</version>
    <exclusions>
        <exclusion>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Also, I used the provided scope for javax.servlet dependencies so as not to introduce an additional conflict with what is provided by Tomcat when I run the app.

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

HTH.

like image 111
barclay Avatar answered Nov 17 '22 09:11

barclay


An addition to the other answers that didn't work for me: In my case the error occurred due to permission errors. The project got deployed while the tomcat was running as root, later when started as tomcat user I got the error from the question title.

Solution in my case was to set the right permissions, e.x. on a unix system:

cd <tomcat-dir>
chown -R <tomcat-user> *
like image 17
Johannes Stadler Avatar answered Nov 17 '22 10:11

Johannes Stadler