Search code examples
javagroovyscriptinggroovyshell

How can I convince GroovyShell to maintain state over eval() calls?


I'm trying to use Groovy to create an interactive scripting / macro mode for my application. The application is OSGi and much of the information the scripts may need is not know up front. I figured I could use GroovyShell and call eval() multiple times continually appending to the namespace as OSGi bundles are loaded. GroovyShell maintains variable state over multiple eval calls, but not class definitions or methods.

goal: Create a base class during startup. As OSGi bundles load, create derived classes as needed.


Solution

  • Ended up injecting code before each script compilation. End goal is that the user written script has a domain-specific-language available for use.