Running JSTL 1.2 on Tomcat 7 using Maven

Okay, I know I haven’t posted anything on my blog in over a year, but this falls under the OMG-Why-Couldn’t-I-find-a-straightforward-answer category. Whomever suffers the same headache I suffered will hopefully get led here by Google…

The Problem: Running the most basic JSP Example

Up until now, the few times I’ve needed to cobble together a JSP file for some sort of front-end functionality, I’ve used raw, low-level JSP Scriptlets. Which means typing things like

<% if (something) { %> <some-html> <% } else { %> <some-html> <% } %>

all over the place. And if I wanted to do any looping, well forget about it! It’s a nightmare. So I’ve got these few books and articles that talk about the better ways to solve these problems using cleaner xml-y solutions, and most all of them dive into using JSTL (JSP Standard Tag Library) which is a damned standard and yet isn’t included with Tomcat. It’s one of those things that each vendor is supposed to implement independently, and yet the only implementation out there appears to be Oracle’s Glassfish implementation! (There’s an Apache JSTL project, and they say on their web page that a version 1.2 implementation (which is the stated version for the Java 6 EE standard collection, alongside Servlet 3.0 and JSP 2.2) but that webpage hasn’t been updated since October 2009!!

So apparently JSTL is so basic and simple that it’s included in the elementary pages of any JSP books, but like some bastard stepchild that nobody wants, it’s support is freakishly missing. Okay, enough bellyaching about how FUBAR that is… what about just getting the thing to run?

Here are some watchas that I ran into…

  • It doesn’t work… until it does. Until I had the right library dependencies working and the right namespace down, I didn’t get any error messages or diagnostics. I just found that my sample <c:forEach> tags would get merely copied into the resulting HTML.
  • The JSP namespace changed. Some early books showed examples where the JSP namespace was written out as xmlns:c="http://java.sun.com/jstl/core" when in fact it later got renamed to xmlns:c="http://java.sun.com/jsp/jstl/core"! Again, no error messages to help me out here. It just didn’t work until it did.
  • Dependency hell, JSTL 2.1 can include the wrong JSP API versions. More on this in the next section.

The good news is you should just be able to grab the Oracle Glassfish implementation JAR, toss that into Tomcat’s lib directory, and stop worrying. But if you use Maven for your dependency management, then life gets crazy again.

JSTL and Maven Dependencies

For the longest time I avoided learning Maven because it just seemed like “just one more thing” and besides, Eclipse seemed to handle all the packaging, etc. just fine. But once I started playing around with XML and SOAP and Web Services and Dependency Injection and Spring and all that really cool stuff, I knew I had to bite the bullet. And I’m glad I did.

Normally if I want to start using some feature (like JSTL) I’ll just do a search in my Eclipse pom dependencies pane, add the dependency and start using the thing. (It’s fantastic!) But unfortunately, Maven dependencies seem to have gotten tripped up when it comes to JSTL 1.2, the bastard stepchild of a dependency. And especially for Tomcat (6 or 7 apparently) which is the “We’re the de-facto standard Servlet 3.0/JSP 2.2 container… except for the JSTL Bastard Stepchild!” server.

When I tried to do a simple dependency inclusion…

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

I got the API, but no runtime libraries. (As I said in the earlier section, this doesn’t result in a compile or runtime error. The JSTL tags simply don’t run and get passed through the outgoing HTML!) So then, after looking for an Apache implementation (I wanted to keep my implementation flavors consistent, and Apache wrote the Servlet 3.0/JSP 2.2 for Tomcat) I decided to include the Glassfish implementation…

<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
</dependency>

and THEN I finally got a runtime exception. But this

javax.servlet.ServletException: 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/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/index_jsp, 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 least this time I got an error message, strange as it was! (And all throughout this experience I didn’t find much of use on the Internet, which is why I’m writing this blog entry.) So at least I got the general idea that there was a revision/dependency problem between the classes. This is why I really hoped to find a JSTL library by Apache—because if you stick with one “flavor” you’re less likely to run into this.

I went into the Dependency Hierarchy tab of my Eclipse POM editor, and I could see that the Glassfish Maven module I’d included also decided to include the Servlet 2.5 and JSP 2.1 libraries. So I was causing a Servlet 3.0/2.5 and JSP 2.1/2.2 clash in my class loader. I clicked on those individual components, right-clicked, asked to remove the dependency, and ended up with this:

<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>

Now to reclaim the hours it took me to get this far! I almost think I should have stuck with the old JSP-style scriptlets all over the place!

Posted in Technology | Tagged , , | Leave a comment

iPad continued… Article about file access

Ted Landau writes a cogent article about the wackiness of iPad’s document access weirdness, specifically with the iWork suite. I’m in complete agreement.

This goes beyond just files, though. As I mentioned in my last post apps like Bento and Things have to set up their own little “standalone syncing servers” that you run on a Mac to synchronize/save data. This is ridiculous! MobileMe sync and Core Data (the latter of which already exists in the iPhone SDK) are already well-thought-out solutions for data synchronization!
Continue reading

Posted in Apple and OS X | Comments Off

Murray’s Reaction to the iPad

During the two-week countdown to the iPad release, for reasons I cannot fully comprehend, I was consumed with anticipation and the need to buy one. Honestly, I am aware that I tend to possess a childlike excitement for various things, like the arrival of a movie that I want to see (e.g. How to Raise a Dragon, Julie and Julia) but the iPad launch completely hit my “little kid on Christmas morning” nerve. Worried that the line to pick up my pre-reserved device would be too long, I showed up outside the NYC 14th Street Apple Store at 6:12am. At about 9:20am my purchase was complete, and I was headed home to try the thing out.

48 hours later, it’s time to write down some of my reactions to this device that has generated so much buzz and so many blog posts and news stories. I’m going to tackle this blog posting in a slightly random way: breaking my reaction into small, isolated snippets.
Continue reading

Posted in Apple and OS X | 9 Comments

Apple’s iPad and Murray’s Old Predictions

Well, the veil has been lifted on the Apple iPad and pundits are busy asking whether there is really such a need for a device in this particular “sub-notebook” niche—especially one at this particular price point.

And once again I shake my head; they just don’t get it… yet. To paraphrase Clinton: “It’s all about the UI, dummy.”

I actually blogged about this well over two years ago. Back when OS X Leopard was coming out (yes, I’m talking about “old” 10.5) there was the introduction of the “Core Animation” API that was the harbinger to things like the sleek iPhone UI and elements popping up on the desktop like the animated “Cover Flow” of iTunes or the Finder.

The iPad will usher in a small but steady revolution as small, intrepid programmers find ways to create very targeted, very specialized apps that make the iPad the perfect tool for business solutions. It will be the architect or interior designer who manages to make a lightweight CAD application that can be really portable, allowing floorplans to be quickly entered into the device while he or she walks through an old house; it will be the medical technician or the factory worker who finally has an application with a user interface that doesn’t force and endless stream of window clicking to enter a simple piece of data; it is the cashier or the maître d’ or the dance choreographer…

Anyway, I suggest anyone interested should actually read that old blog article I wrote in 2007. It still applies.

Posted in Apple and OS X | 8 Comments

Losing Faith in Banks

I have two banks. One is a credit union that was based in Fort Collins with whom I had been a member since 1988. It’s name was Norlarco but is no more because it died and was merged with another Denver-based credit union. From what I hear, Norlarco’s board allowed someone to make risky investments in Miami property and that essentially killed it. (Ironically, when I was wanting to buy a home in Los Angeles they told me they couldn’t help me unless it was in Colorado. I guess I didn’t grease enough palms!) The biggest pain has been changing my checks and all of the settings for all my various auto-payments, from utilities to Netflix. Ugh.

Last year I opened an account at Washington Mutual because I neede the convenience of a local bank here in New York. As everyone knows, that died and got sold to JPMorganChase.

Now my drama continues with credit cards. I was notified last month by my credit union that due to an internal security breach all their debit cards were comprimised and would have to be replaced. New card just showed up in the mail. New PIN for me to memorize.

Last night I just got an e-mail from USAA (a credit card issuer) stating that there’s been a security breach, and they are going to have to replace my credit card.

This is crazy! I’m just about ready to start stuffing money into my mattress!

Posted in Life | Leave a comment