Pretty Good WebApp Setup
As with most hackers, I am easily lead down the MVC framework rabbit hole. These days I tend towards light-touch simplicity over hulking great know-it-alls. The Rails, Spring MVC and Django’s of this world have their place, but I’d rather have the routing done by something that cares about routing, the templating done by a templater and persistence left to the dark lords.
Cursed by the Java affliction for the past 3 years, options have been few and generally unappealing. Guice MVC gets the closest, but for some reason I just can’t get on with her. I’ve almost gone full circle with Java, tending to use the Servlet API directly with a .war that will run with an embedded Jetty (under guidance from @ayrez at MetaBroadcast).
I have recently been released, if temporarily, from Java’s shackles so have been tinkering with Scala (I think actual dynamic typing would give me the bends this soon). Scala also has it’s all singing, all dancing, web framework in Lift (which looks fine) but also has a good set of separate projects that take care of the various parts of the problem:
- Scalatra: a port of Ruby’s excellent Sinatra, just for routing
- Scalate: templating engine with all your popular formats
- simple-build-tool (sbt): builds on the good bits of maven and ivy, but with actual code configs
- Bowler: that ties all these together in a generally sensible way
I also found @glen_ford’s plugin for sbt that will package .wars with an unpacked jetty, so you can run them with `java -jar`.
All together, this makes for a pretty good web-app setup. I’ve pushed my test project to a Github repo for reference. It means you get to write really simple controllers with their own routing and have the lightest of bootstrapped dependency injection.
However, getting to this place has not been without its problems. These technologies range from very immature to fairly immature so inevitably need some work. Here are a list of gripes and gotchas that will hopefully not put you off these things that I’ve just said I liked:
- Scalate is slow. It is handy, it is pretty trendy, but it is the slowest thing in this stack and, while we’re taking about adding a millisecond or-so to the request, it could definitely do with some tuning under heavy load.
- Scalate requires that you add the scala-compiler.jar to a lib/ folder to run the project with Java.
- I had to go with a Bowler SNAPSHOT version to make use of a small issue fix. This is not a problem really. Bowler seems to get a lot of love from @wfaler, even if a lot of it goes towards the persistence side of things.
- sbt takes some getting used to and I seem to need to `compile` before I `package`, which I think is todo with the plugin.
Now I just need to make something useful with it…