tags:

views:

122

answers:

1

I am developing a webapplication in Clojure and Vaadin, but I cannot get the application to autoredploy so that I just press refresh on the browser. Any ideas?

+1  A: 

Ideally, you're using a REPL server that will allow you to load new Clojure code into your application at will. In that case, it's just a matter of changing your workflow to:

  1. notice problem
  2. go to Clojure editor
  3. Load new code into running application
  4. Go to browser, hit refresh.

If you're using Maven, you can use the maven-jetty-plugin to automatically reload your webapp when you change its source files. See this post for more info.

Yet another options is to continuously attempt to reload your Clojure code. Something like this, perhaps:

(defn reload
  ([] (reload #"."))
  ([ns-pattern]
    (doseq [ns (all-ns)
            :let [ns (.name ns)]
            :when (re-seq ns-pattern (str ns))]
      (require ns :reload))))

In whatever code you have that starts up your webapp, or in your main servlet init, etc., add something like:

(future (loop []
          (Thread/sleep 5000)
          (reload) ;; optionally specify a regex to match only your app's namespaces here
          (recur)))

Definitely not something you want to use in production. I'd prefer using a proper remote REPL in every case, but the above will get you by.

Chas Emerick
I tried this but it doesn't work with Vaadin. Could you give more details please?
Zubair