groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Henry <>
Subject No Such Property - When executing script from Java.
Date Wed, 17 Jun 2015 01:57:44 GMT
Hi All,

I am trying to run a groovy script from Java and getting the following error

<quote>Exception in thread "main"
org.codehaus.groovy.runtime.metaclass.MissingPropertyExceptionNoStack: No
such property: formFilled for class: Bugger</quote>

My script looks like this.

class Action {
    String actionName
    Action(actionName) {
        this.actionName = actionName;
    void execute() {
        println "Doing $actionName"

formFilled = new Action("Form Filled")

mailSent = new Action("Mail Sent")

def invoke(action) {

//----- These are runnable when run as a script.

If i execute the script directly then the last two lines execute and
produce the expected Strings printed to the standard out.

Doing Form Filled
Doing Mail Sent

I am trying to run it from Java with something like the following.

Class scriptClass = new GroovyClassLoader().parseClass(new
Object scriptInstance = scriptClass.newInstance();
scriptClass.getDeclaredMethod("invoke", new Class[]
{}).invoke(scriptInstance, new Object[] {"formFilled"});

But I keep getting the No Such property exception. Ive looked around for
solutions, but either Im missing something so basic its generally
understood, or i haven't found the right part of the internet.

So Two questions.

1) why is the property not available / hidden. I don't understand why its
not available to a method within what I expect is the class.

2) what change do I have to make to my code snippets to get it to work.

(Note: I've created a simple example of the problem, rather than post my
actual code. I am using groovy to define a DSL for describing actions. We
then parse a script in that DSL defining different actions. During
operation we want to trigger individual actions to execute on certain



Paul Henry
Senior Technical Developer |
79 Boulcott Street, Level 2, Wellington 6011, New Zealand

tel +64 4 499 1327 | mob +64 22 161 8700 | | LinkedIn

View raw message