You can write an external Groovy script that does all the import, creates a GroovyConsole object, and calls the run () method on that object.
See also http://groovy.codehaus.org/Groovy+Console#GroovyConsole-EmbeddingtheConsole
For example: start.groovy
import groovy.ui.Console; import com.botkop.service.* import com.botkop.service.groovy.* def env = System.getenv() def service = new ServiceWrapper( userName:env.userName, password:env.password, host:env.host, port:new Integer(env.port)) service.connect() Console console = new Console() console.setVariable("service", service) console.run()
The Groovy executable is called from the shell script, giving it the Groovy script:
#!/bin/bash if [ $# -ne 4 ] then echo "usage: $0 userName password host port" exit 10 fi export userName=$1 export password=$2 export host=$3 export port=$4 export PATH=~/apps/groovy/bin:/usr/bin:$PATH export CLASSPATH=$(find lib -name '*.jar' | tr '\n' ':') groovy start.groovy
Now, GroovyConsole code can now use the import made in start.groovy, as well as from variables created and passed using the setVariable ("service" method in the example).
botkop
source share