Issues while migrating from Jetty to tomcat 7

If you use Jetty for development of web apps and have to deploy to a tomcat 7 container, you’ll probably get some unpleasant error messages on start up, especially if you use JSTL.

One of these issues might be:

SEVERE: Servlet.service() for servlet [jsp] in context with path [] threw exception [java.lang.AbstractMethodError: javax.servlet.jsp.JspFactory.getJspApplicationContext(Ljavax/servlet/ServletContext;)Ljavax/servlet/jsp/JspApplicationContext;] with root cause

java.lang.AbstractMethodError: javax.servlet.jsp.JspFactory.getJspApplicationContext(Ljavax/servlet/ServletContext;)Ljavax/servlet/jsp/JspApplicationContext;

In your log output. The reason for that is that JSTL is included in tomcat and and your JSP api might just be too old. Tomcat 7 comes with Servlet 3.0 and JSP 2.1 support built in, so make sure you replace the relevant sections in your pom.xml with this:

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>servlet-api</artifactId>

<version>2.5</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>jstl</artifactId>

<version>1.2</version>

</dependency>

<dependency>

<groupId>org.glassfish.web</groupId>

<artifactId>jstl-impl</artifactId>

<version>1.2</version>

<exclusions>

<exclusion>

<artifactId>servlet-api</artifactId>

<groupId>javax.servlet</groupId>

</exclusion>

<exclusion>

<artifactId>jsp-api</artifactId>

<groupId>javax.servlet.jsp</groupId>

</exclusion>

<exclusion>

<artifactId>jstl-api</artifactId>

<groupId>javax.servlet.jsp.jstl</groupId>

</exclusion>

</exclusions>

</dependency>

<dependency>

<groupId>javax.servlet.jsp</groupId>

<artifactId>jsp-api</artifactId>

<version>2.1</version>

<scope>provided</scope>

</dependency>

Please note that you should check the contents of your target/<webapp>/WEB-INF/lib for remnants of other implicit dependencies. You might have a servlet-api-3.0.jar in there. If that’s the case, change the servlet-api dependency to:

<dependency>
  <groupId>org.glassfish</groupId>
  <artifactId>javax.servlet</artifactId>
  <version>3.0</version>
  <scope>provided</scope>
</dependency>

Make sure that your WEB-INF/lib directory is clean.

Especially the bit the exclusions are important, as they prevent JSTL from importing the servlet and jsp apis by implicit dependency. See this post in Stackoverflow for a description. Another excellent post on this subject is to be found here.

In cases of this error:

SEVERE: Servlet.service() for servlet [app] in context with path [/scheduler] threw exception [javax.servlet.ServletException: java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;] with root cause

java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;

you’ll need to add the jstl-impl jar with the following maven dependency.

<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
<exclusion>
<artifactId>jsp-api</artifactId>
<groupId>javax.servlet.jsp</groupId>
</exclusion>
<exclusion>
<artifactId>jstl-api</artifactId>
<groupId>javax.servlet.jsp.jstl</groupId>
</exclusion>
</exclusions>
</dependency>

 

Advertisements
This entry was posted in Enterprise Java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s