Jan 16 2014

Using Webjars without Servlet 3 on Google App Engine (GAE)

I recently stumbled upon what is just about the best thing since I first discovered the wonders of maven – the ability to add javascript dependencies in your pom.xml using webjars.  Like this:

Maven will manage their sub-dependencies and  your web pages can access the scripts direct from the jars.  Lovely.  Sign me up!  Except wait, what?  Webjars requires servlet 3 and GAE only supports 2.5.  Boo.  Thanks Google.

Google have been quick off the mark unable to deal with this at all.  There’s a fairly funny unsolved support request from way back in 2010 about it here .

Frustrated about this, and really surprised there was no existing workaround anywhere, I braved about eleventy million not particularly helpful bits of restlet documentation and finally came up with a workaround.  Yay!

You’ll need restlet for this, I expect you could use restlet just for this around the rest of your <insert framework here> app, but as I’m using restlet anyway it works a treat.

This took me ages because the RESTlet website has been utterly broken for months and RESTlet behaves really rather oddly sometimes.  It’s impossible to get hold of the application within the router and add the CLAP protocol (getApplication() is returning null) and if you attempt to add the correct client connector when building the application itself it somehow forgets by the time you get to the router.  I’ve still no idea why.

What you can do is either (a) create a new component with a new context and add the CLAP protocol to it, or (b) modify your init-parms in the web.xml to contain CLAP, like so:

The add a new component workaround will log “SEVERE don’t do this” style warnings when you start up, so it’s best to do it in the web.xml if possible.

3 comments on “Using Webjars without Servlet 3 on Google App Engine (GAE)

  1. Pingback: Controlling the cache headers for a RESTlet directory

  2. Hi, I tried to follow this recipe, but could not get it working… Was not sure if I need to create a Router object and how that integrates with Google App Engine. Would you happen to have a working GAE repo that serves static content from a webjars archive so I can see what I screwed up? (bear with me, I am trying to return to web development after 15 year lapse). Thanks in advance!

Leave a Reply