Access the Grails domain class from GroovyShell script

I am trying to use GroovyShellGrails to evaluate some code fragments, but it seems to me to have access to our Grails domain classes. For example, when I try to evaluate something like this:

Eval.me("my.package.MyDomainClass.get(1)")

I see this error:

groovy.lang.MissingPropertyException: No such property: my for class: Script1

Any thoughts on how I can make this work?

Thank.

+3
source share
1 answer

, . GroovyShell script , Grails . , , , Grails (, grails console):

def shell = new GroovyShell(this.class.classLoader)
shell.evaluate("my.package.MyDomainClass.get(1)")
+6

Source: https://habr.com/ru/post/1785904/


All Articles