Java code hot-replace|reload with JDK's Java Compiler or groovy

915 views Asked by At

It seems to me that with the JDK's javax.tools.JavaCompiler there should be an easy way to improve developer's productivity by live code-replace (a'la JRebel, but with more generic way). My idea is that I launch my app, edit the Java sources (suppose outside of the IDE) and the running code will refresh itself with the new sources automatically. (no manual compile or any other action should be required on the developer's side).

Does anyone has a working prototype?

My other idea would be to use groovy to reload the Java classes (thus, using Groovy only for development but not for runtime).

ps. I know Eclipse Java debugger has this, but that is suboptimal.

1

There are 1 answers

2
Todd W Crone On BEST ANSWER

There is only a couple ways I've had much success with hot code-replace on the JVM NOT inside of a Grails project. Both were with Spring:

1) Use a scripted bean written in Groovy/Ruby/Beanshell with either 'refresh' or 'reload' set in the configuration (can't remember which right now but I can find if necessary) -> http://static.springsource.org/spring/docs/2.0.5/reference/dynamic-language.html

2) Start out using a Groovlet -> http://groovy.codehaus.org/Groovlets

3) If you have a Spring bean class, I seem to remember recompiling then having a script take a class file and overwriting on Tomcat with some success a while back. I think the Spring proxy might make this work but it has been a while since I messed with this.

Good luck!