How To Integrate Clojure Web Applications in Apache

I use a combination of the following to make this fairly painless:

Cake (incl. the deploy command)

A Cake template for webprojects developed by Lau Jensen.

Vagrant (Ruby VM(Virtualbox) management tool, which relies on Chef or Puppet)

VPS (from Slicehost)

The key part is the webdev template that Lau made. The webdev folder should be placed in the ~/.cake/templates. To create a new project based on it use:

cake new webdev *projectname*

Pls note that the template includes log4j and Java mail which can/should be excluded if not needed. It further assumes you are using Enlive and Moustache but changing that to Compojure/Hiccup is trivial if that is your poison.

The template takes care of serving the app from jetty in development (you just eval server.clj) and works as a war when running under Tomcat. Routes remain identical if deployed to the server as ROOT.war under Tomcat. All static files should be located in the resources dir. Jetty will serve them from there (thanks to the Ring file middleware). In production these are moved to the root of the webapp and served from there by Tomcat(the web.xml takes care of that).

The devbox folder contains a Vagrantfile and cookbooks necessary to create a Virtualbox VM with Tomcat installed. I use cake to deploy the .war file to the /home/vagrant dir (this is controlled from the definition of the dev context in project.clj). The .war file is symlinked into Tomcat’s webapps dir (/var/lib/tomcat6/webapps) as ROOT.war. For further info on how to use Vagrant please see the Vagrant site.

This gist shows an example of how to adapt the project.clj to use the cake deploy command. The example creates two contexts @dev and @prod which you can deploy to using:

cake deploy @dev / cake delpoy @prod

I have collected the Cake webdev template and the Vagrant files in this zip.

Leave a Comment