Re:

2023-11-12 Thread Paul King
You seem to be wanting to access script bindings but are supplying an
explicit class that isn't a script (doesn't extend Script).
I'd just replace your script definition with this:

final String SCRIPT = "println \"Hello ${foo}\"";

Cheers, Paul.


Virus-free.www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Mon, Nov 13, 2023 at 4:50 AM Jochen Wiedmann
 wrote:
>
> Hi,
>
> could anyone, please, explain to me what to fix in the script below? I
> am getting the error message below:
>
> Thanks,
>
> Jochen
>
>
> <<>>
> : Apparent variable 'foo' was found in a static scope but doesn't
> refer to a local
> variable, static field or class. Possible causes:
> You attempted to reference a variable in the binding or an instance 
> variable
>  from a static context.
>  You misspelled a classname or statically imported field. Please check the
>  spelling.
>  You attempted to use a method 'foo' but left out brackets in a place not
>  allowed by the grammar.
>  @ line 7, column 22.
>  demo.foo = "${foo}";
> <<>>
>
> My Java class looks like this:
>
> <<>>
>  public static void main(String[] args) {
> final String SCRIPT =
> "public class Demo {\n"
> + " public void run() {\n"
> + " System.out.println(\"Hello ${this.foo}\");\n"
> + " }\n"
> + " public static void main(String[] args) {\n"
> + " Demo demo = new Demo().run();\n"
> + " demo.foo = \"${foo}\";\n"
> + " }\n"
>  + "}\n";
> final GroovyShell gsh = new GroovyShell();
> final Map parameters = new HashMap<>();
> parameters.put("foo", "World");
> final Script script = gsh.parse(SCRIPT, new Binding(parameters));
> script.run();
> }
> <<>>
>
>
>
>
> --
> The woman was born in a full-blown thunderstorm. She probably told it
> to be quiet. It probably did. (Robert Jordan, Winter's heart)


[no subject]

2023-11-12 Thread Jochen Wiedmann
Hi,

could anyone, please, explain to me what to fix in the script below? I
am getting the error message below:

Thanks,

Jochen


<<>>
: Apparent variable 'foo' was found in a static scope but doesn't
refer to a local
variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable
 from a static context.
 You misspelled a classname or statically imported field. Please check the
 spelling.
 You attempted to use a method 'foo' but left out brackets in a place not
 allowed by the grammar.
 @ line 7, column 22.
 demo.foo = "${foo}";
<<>>

My Java class looks like this:

<<>>
 public static void main(String[] args) {
final String SCRIPT =
"public class Demo {\n"
+ " public void run() {\n"
+ " System.out.println(\"Hello ${this.foo}\");\n"
+ " }\n"
+ " public static void main(String[] args) {\n"
+ " Demo demo = new Demo().run();\n"
+ " demo.foo = \"${foo}\";\n"
+ " }\n"
 + "}\n";
final GroovyShell gsh = new GroovyShell();
final Map parameters = new HashMap<>();
parameters.put("foo", "World");
final Script script = gsh.parse(SCRIPT, new Binding(parameters));
script.run();
}
<<>>




-- 
The woman was born in a full-blown thunderstorm. She probably told it
to be quiet. It probably did. (Robert Jordan, Winter's heart)