|
Hi.
I am J2EE developer, working on an Eclipse/Maven2 environment and I would like to use the functionnalities of Groovy to dynamically compile a Groovy class used in a Java project. My goal is to be able to modify my Groovy sources without having to relaunch the compilation each time. Moreover, I would like to outsource my Groovy source file and load it dynamically using Java object like the groovy.lang.GroovyClassLoader (Groovy API) or similar. I did not find any concrete solution on the web, neither on Groovy web site, that's why, I post this message. Could anyone, experienced with the Groovy language, help me solving my problem ? Thank you in advance for your ideas. |
|
See the section entitled "Dynamically loading and running Groovy code inside Java":
http://docs.codehaus.org/display/GROOVY/Embedding+Groovy Tom On Tue, Feb 21, 2012 at 5:18 PM, Vivien De Horta <[hidden email]> wrote: Hi. |
|
In reply to this post by Vivien De Horta
Hi Viven,
another hint might be CompilerConfiguration.recompileGroovySource [0] and GroovyClassLoader.shouldRecompile [1], depending on the Groovy classes your implementation chooses to load scripts. Cheers, André [0] http://groovy.codehaus.org/api/org/codehaus/groovy/control/CompilerConfiguration.html [1] http://groovy.codehaus.org/api/groovy/lang/GroovyClassLoader.html |
|
Thank you for your help.
I got no satisfying result with the GroovyClassLoader which seemed to be the most appropriate object for my problem but I am now looking for a mean to make the GroovyScriptEngine work with a Groovy class instead of a script (I have tested with a basic script and it works very well). The groovy.runtime.InvokerHelper may contains interesting methods to solve my problem. Concerning the GroovyClassLoader, if anyone has a working source example, I would be glad to see it (I need to use the setShouldrecompile, loadClass and maybee clearCache methods). 2012/2/22 Andre Steingress <[hidden email]> Hi Viven, |
|
This post was updated on .
Hi Vivien,
Maybe you can come up with a code sample of what you're actually trying to achieve. Btw, I once wrote an article on how Spring's Groovy support is implemented: http://blog.andresteingress.com/2010/04/13/groovy-in-spring-applications/ Might be interesting to have a look at their sources (especially GroovyScriptFactory) and how Groovy class reloading is done in the Spring environment. Cheers, André On Wednesday, February 22, 2012 at 3:07 PM, Vivien De Horta wrote: > Thank you for your help. > > I got no satisfying result with the GroovyClassLoader which seemed to be the most appropriate object for my problem but I am now looking for a mean to make the GroovyScriptEngine work with a Groovy class instead of a script (I have tested with a basic script and it works very well). The groovy.runtime.InvokerHelper may contains interesting methods to solve my problem. > > Concerning the GroovyClassLoader, if anyone has a working source example, I would be glad to see it (I need to use the setShouldrecompile, loadClass and maybee clearCache methods). > > > > 2012/2/22 Andre Steingress <me@andresteingress.com (mailto:me@andresteingress.com)> > > Hi Viven, > > > > another hint might be CompilerConfiguration.recompileGroovySource [0] and > > GroovyClassLoader.shouldRecompile [1], depending on the Groovy classes your > > implementation chooses to load scripts. > > > > Cheers, André > > > > [0] > > http://groovy.codehaus.org/api/org/codehaus/groovy/control/CompilerConfiguration.html > > [1] http://groovy.codehaus.org/api/groovy/lang/GroovyClassLoader.html > > > > -- > > View this message in context: http://groovy.329449.n5.nabble.com/How-to-dynamically-compile-Groovy-class-tp5502842p5504393.html > > Sent from the groovy - user mailing list archive at Nabble.com (http://Nabble.com). > > > > --------------------------------------------------------------------- > > To unsubscribe from this list, please visit: > > > > http://xircles.codehaus.org/manage_email > > > > > |
|
Thank yuo, I am going to read your article.
I finally succeeded in resolving my dynamic compilation challenge using the GroovyClassLoader.parseClass method. Thank you for your help. Vivien. 2012/2/23 Andre Steingress <[hidden email]>
|
| Powered by Nabble | Edit this page |
