Apr 12

Run ClojureScript One from Eclipse

ClojureScript is an exciting project which allows you to write your browser JavaScript code in Clojure. ClojureScript One is a sample project of a web app which is written entirely in Clojure(server, client and… communication protocol :). Recently I wanted to play with this sample app in Eclipse using CCW plugin. I realised that I could launch the dev server but somehow JavaScript couldn’t be compiled properly and I got a bogus error “Can’t recur here” from the ClojureScript compiler.

The problem was because of the CCW plugin that was ahead of time compiling Clojure source files to Java classes. The solution is to prevent it from doing so. With CCW 0.5 simply remove classes from the build path, with CCW 0.6 additionally delete the classes directory from the disk drive.

Here is a pretty detailed description of my workflow while  starting the ClojureScript One in Eclipse:

  1. Clone ClojureScript One with Git to the workspace
  2. Run lein bootstrap in the ClojureScript One root
  3. Run lein pom
  4. Import existing maven project into Eclipse
  5. Manually add all the entires from project.clj to the build path (:source-path and :extra-classpath-dirs keys)
  6. Right click on project and Enable Clojure support
  7. Remove classes directory from the build path (might need to delete the directory)
  8. Run project as Clojure application
  9. Load the one.sample.repl namespace (load file and switch to the namespace) into the REPL and run (dev-server)
  10. Navigate to the web app’s development tab to see if you get any errors.
It works and here is the proof:

ClojureScript One in Eclipse  - Windows

Note: don’t run (go) from the REPL in CCW because the ClojureScript REPL is incompatible with nrepl. In order to use the cljs repl stick to the simple console and run it from “lein repl”. Any questions? Don’t hesitate to ask.

Hope it works for you as it worked for me. Don’t be scared with all the steps and remember that ClojureScript is in alpha yet. To be honest I often end up messing with pure Java projects in similar fashion.

Leave a Reply

Your email address will not be published.