I'm trying to embed groovy into a large Java application.
The Java application should load some utility Groovy scripts at startup.
The application should then run other scripts multiple times. There is also a need to enter some code at a GUI and execute it at user request.
The problem I'm facing is this:
I am loading the startup script like this:
GroovyShell gShell = new GroovyShell();
gShell.evaluate(new FileReader("scripts/autoload.groovy"));
Suppose my autoload.groovy contains:
def prnt(m) {
println("From Groovy: " + m);
}
This works fine. But when I want to run a user command using:
gShell.evaluate("prnt 66");
I get the error:
groovy.lang.MissingMethodException: No signature of method: Script2.prnt() is applicable for argument types: (java.lang.Integer) values: [66]
How can my user script access the methods already loaded?
Note: I have also tried "autoload.prnt 88", and still get the error.