javaclojure

Reload a Java class in Clojure


I would be interested in reloading a Java class in Clojure, for example in the REPL.

If a Java class has previously been loaded and used, and, afterwards, it has been changed and recompiled, can the new updated class be reloaded?

I have done some searches (for example, How does clojure class reloading work?), but I have not found a clear way to do it.

Thanks.


Solution

  • You can use a modified JVM that you can use with Clojure to accomplish that, DCEVM. I made a small project to demonstrate how to set it up. DCEVM will automatically reload Java classes in a running JVM process when those classes are updated. The good thing with DCEVM is that you don't have to pay for it. DCEVM seems to work most of the time, but not always. Sometimes I have to restart the REPL to get the new clases loaded.

    Before using DCEVM I tried JRebel. Just like DCEVM, JRebel will also reload Java classes. In my experience, JRebel worked a lot more reliably than DCEVM, but unfortunately it is quite expensive to buy. You can try it out, though, for a limited time period for free.

    Update: I found this answer too, which seems quite consistent with what I wrote regarding DCEVM vs JRebel.