Clojure Cursive: Write, Run, Deploy

Some quick notes on writing, running and deploying Clojure apps.

When using Cursive for IntelliJ, a default Leiningen project is easiest for development. However, using the ‘app’ template in Leiningen sets up a default runnable app that can be packaged quickly into an uber JAR.

I suggest doing most of the application development with a default project, and then use an ‘app’ project for the deployment.

The default template for ‘app’ is as follows.

To run a default app, use the lein run command from the command line. To create runnable JAR from the app template, use the command lein uberjar. You can then run the standalone JAR created in the ‘target/uberjar’ directory of the project.

Using the REPL with App Templates

When using the REPL in Cursive from an app template, you might have to set up the run configuration and then register the project.clj with the run configuration. Even once you have stumbled through that process, you may find that you have to change the name space to match you core.clj file’s namespace. And finally, you’ll likely need to load the -main function into the namespace. At that point you should finally be able to run (-main) from the REPL.

That’s why I do most of my regular development from inside a default lein project instead of the app template.