Search code examples
groovygroovy-console

Groovy Console with defaulted imports


Is there a way to start the groovy console with a set of imports already set or variables predefined?

java -cp <some jar with groovy> org.codehaus.groovy.tools.shell.Main

But before the user even does anything several things have been already imported for them, such as static functions or classes.


Solution

  • Is there a way to start the groovy console with a set of imports already set or variables predefined?

    You can specify expressions to be evaluated at startup time using the -e command line switch:

    groovysh -e "x=5;y=4"