Is it possible to execute groovy code dynamically loaded into a java application. For example, there is a database table containing small pieces of groovy code, for example:
def test(${val_to_insert_from_java}){
if (${val_to_insert_from_java} > 10){
return true;
}
return false;
}
Where ${val_to_insert_from_java}is a placeholder for some real value that will be inserted during java code execution, for example:
String groovyFuncSource = getFromDb();
groovyFuncSource.replace(${val_to_insert_from_java}, 9);
Object result = <evaluate somehow groovyFuncSource>;
Is there any way to evaluate such a piece of groovy code? Or maybe you would advise me on a different approach on how to implement this.
source
share