2

I often want to test methods I'm developing in a Groovy class independently, and use the Console to do so, like:

groovyConsole -cp mygroovyfiles

However I have not yet been able to figure out how to reload changes to my groovy files so that I can update the files and see the results reflected in the Console. "/Script/Add Directory to ClassPath" and "Script/Clear Script Context" don't work. Is this possible?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Josh Diehl
  • 2,913
  • 2
  • 31
  • 43
  • I have strange problems with menu "add JARs to classpath" http://stackoverflow.com/questions/32494835/what-is-classpath-for-groovy-console-jdbc-driver-prblem?noredirect=1#comment52852295_32494835 – Jacek Cz Sep 11 '15 at 06:21

2 Answers2

3

I don't believe it is possible in the groovyConsole. The groovysh, however, is a different story. The groovysh has a \l command which lets you reload a script. I don't know if this helps you, but it works for me. A session would look like this...

bobk-mbp:~ bobk$ cd work/workspace/ZGroovyProject/
bobk-mbp:ZGroovyProject bobk$ emacs src/Hello.groovy 
bobk-mbp:ZGroovyProject bobk$ groovysh
Groovy Shell (1.8.3, JVM: 1.6.0_29)
Type 'help' or '\h' for help.
-----------------------------------------------------------------------------------------------------------------------------------
groovy:000> \l src/Hello.groovy 
hello, world.
===> null
groovy:000> \l src/Hello.groovy 
hello, world from bob
===> null
groovy:000> 
Bob Kuhar
  • 10,838
  • 11
  • 62
  • 115
  • Have yet to hear anyone else say it's possible so I guess not. groovysh should fit my needs, I'll check it out. – Josh Diehl Dec 08 '11 at 04:47
  • Only works for scripts, not compiled classes loaded from the classpath (as far as I can tell). :purge didn't help either. – Bill K Nov 01 '18 at 16:53
2

You may try to clean your buffer before you reload the script

>clear
>load src/Hello.groovy
XianGuang
  • 21
  • 2