Feb 19

Tutorial: How to set up Tomcat 6 to work with JSTL 1.2

Tag: development, java, jsp, jstl, spring, tomcatpmularien @ 11:37 pm

Tomcat 6 does not ship with an implementation of JSTL. I decided to write up this quick start guide, since it’s really, really hard for new folks to know how to get started with Spring MVC (which is very often combined with JSTL) on Tomcat 6.

Sadly, Sun’s JSTL site does not even point you at the actual reference implementation of JSTL 1.2 (at least there’s no very obvious link that I have been able to find - but what good would a Sun web site be if it was easy to find what you were looking for? ;) ).

The Apache Jakarta Taglibs project is the source of JSTL 1.0 and 1.1 reference implementations, but it is no longer maintained and will never implement JSTL 1.2.

The JSTL 1.2 reference implementation has been folded into the Glassfish application server. It seems that Sun in its infinite wisdom has decided to make the reference implementation almost impossible to find. The link to “Reference Implementation” on the JSR-052 page points you to the Sun Java EE download page (argh!)

So, how do you get this installed on Tomcat?

  • Download the latest version of Glassfish V2 application server here.
  • Unzip/install to a directory
  • From the “lib” directory of the install, copy as follows:
    • appserver-jstl.jar: Place in the WEB-INF/lib directory of your web application. This is preferable because you can ensure that the correct version of JSTL lives with your application. Note you may run into classloader issues when running on application servers other than Tomcat which supply their own (conflicting) JSTL implementations. In this case, remove this JAR from your web application, and move it into {tomcat-install}/lib.
    • javaee.jar: In the {tomcat-install}/lib folder. This will make the JSTL 1.2 libraries available to all web applications.

Note that placing javaee.jar in the app server lib directory isn’t really the best way to go about this, but Tomcat will ignore the JAR if it’s included in your webapp due to the rule in section 9.3.2 of the Servlet 2.3 spec (in fact, it will ignore any JAR file completely if it contains the class javax.servlet.Servlet). For further reference, you can see the classloader code. You will see the following error when your webapp is started up if you have javaee.jar in WEB-INF/lib (assuming appropriate logging is enabled):

INFO: validateJarFile({path-to-webapp}\WEB-INF\lib\javaee.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2.
Offending class: javax/servlet/Servlet.class

For you Spring MVC’ers trying to get started with the latest versions of Tomcat and JSTL, hopefully this helps you!

11 Responses to “Tutorial: How to set up Tomcat 6 to work with JSTL 1.2”

  1. Christian Ullenboom says:

    A litte sidenote: With Glassfish v3 the Jars are under /modules and named e.x. jstl-api-1.2.jar.

  2. pmularien says:

    Thanks, I’ve updated the content to specify v2, until v3 stabilizes a bit more.

  3. newbie says:

    So the only way is to install them in the tomcat lib directory? In other words, I can’t have them in just my application’s lib directory, i.e., /WEB-INF/lib ?

  4. pmularien says:

    Indeed you can - I must have missed that [highly preferable] option when I reviewed this entry prior to posting. I’ve revised it listing both the WEB-INF/lib and Tomcat lib directories as choices. Thanks for the feedback!

  5. Frederic Filiatrault says:

    Hi pmularien,

    After loosing about 2 hours saying: “WTF happened with Tomcat?@##@)@(%*#)@( *”, I found your website.

    Pray the Lord! You described exactly what I have found but was not sure. How come Tomcat, which is a fair web container IMHO can intentionally omit JSTL jars?!?

    Anyway, many thanks for your page on this!

  6. It’s Only Software » How to Reference and Use JSTL in your Web Application says:

    […] Of these, JBOSS and Glassfish ship with JSTL implementations out of the box. Tomcat does not ship with a JSTL implementation. I have previously blogged about this here. […]

  7. Sam Weinger says:

    Am I the only one who is unable to get this to work without placing javaee.jar in {tomcat-install}/lib? Otherwise the webapp class loader is unable to find classes that implement the tags.

  8. pmularien says:

    Sam,

    I have seen that behavior too, since I posted this article. I’ve been meaning to dig into it a little more, and your comment has pushed it up on the priority list. Look for an update soon!

    Peter

  9. pmularien says:

    So, it seems that Tomcat will not recognize j2ee.jar if it’s included only in your webapp. This is because Tomcat is coded to ignore any JAR file containing classes from javax.servlet, which j2ee.jar does (along with a whole host of other stuff). It looks like, unless you want to create a j2ee.jar with the javax.servlet stuff elided. I’ll update the article to reflect this. At minimum, it seems you need j2ee.jar in (tomcat-install)/lib, and appserv-jstl.jar can reside with your webapp.

  10. Dylan MacDonald says:

    God how I wish this worked. The version of glassfish you cite does not have the files you mention. Well, it does but they are archived as appserv-jstl.jar.pack.gz and javaee.jar.pack.gz. Easy to unarchive .gz files, but I could not for the life of me find what .pack files are and how to unarchive them. I swear I hate development sometimes. Everything has to be so damn difficult.

  11. pmularien says:

    @ Dylan -

    Make sure you run the step of the Glassfish “install” process that includes executing the ’setup.xml’ ant script. This is the step that will unpack those files. Alternatively, I believe the Sun distribution of Glassfish will unpack when you run the installer.

    Good luck!
    Peter

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>