I'm loading a groovy script file dynamically with GroovyClassLoader
In the script file I have this code
def var = false;
void run() {
if(var == false) {
...
}
}
though I have declared the variable "var" in the script file I'm getting the
error when call the function run().
Caught: groovy.lang.MissingPropertyException: No such property: var for
class: foo
Thanks.
--
View this message in context: http://old.nabble.com/dynamic-loading-script-file---no-such-property%3A-error-tp26722825p26722825.html
Sent from the groovy - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
def var = false
boolean run() {
return (var == false)
}
assert run() == true
What works for me is:
def var = false
def run = {
return (var == false)
}
assert run() == true
Does that help at all?
On Wed, Dec 9, 2009 at 10:51 PM, prabuinet <prab...@gmail.com> wrote:
>
> Hi!
>
> I'm loading a groovy script file dynamically with GroovyClassLoader
> In the script file I have this code
>
> def var = false;
>
> void run() {
> if(var == false) {
> ...
> }
> }
>
>
> though I have declared the variable "var" in the script file I'm getting the
> error when call the function run().
>
> Caught: groovy.lang.MissingPropertyException: No such property: var for
> class: foo
---------------------------------------------------------------------
Caught: groovy.lang.MissingMethodException: No signature of method:
foo.run() is applicable for argument types: () values: {}
--
View this message in context: http://old.nabble.com/dynamic-loading-script-file---no-such-property%3A-error-tp26722825p26723279.html
Sent from the groovy - user mailing list archive at Nabble.com.
void run() {
if(var == false) {
...
}
}
Ooh! "var' is not in other module.. it is in the same script file.
--
View this message in context: http://old.nabble.com/dynamic-loading-script-file---no-such-property%3A-error-tp26722825p26724198.html
I have the following config file (build.properties) :
target = foo
source = bar-buh
the following code works intentionally:
def props = new Properties()
props.load(new FileInputStream(new File('build.properties')))
def config = new ConfigSlurper().parse(props)
println config.source
the following code fails:
def c = new ConfigSlurper().parse(new File('build.properties').toURL())
println c.target
Exception in thread "main" groovy.lang.MissingMethodException: No
signature of method: groovy.util.ConfigObject.minus() is applicable for
argument types: (groovy.util.ConfigObject) values: {[:]}
at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:172)
at script1260439847206.run(script1260439847206.groovy:2)
Shouldn't these two ways of loading a configuration be equal ?
Thx
Andreas
--
Andreas Jöcker
GiS - Gesellschaft für integrierte Systemplanung mbH
Junkersstr. 2
69469 Weinheim
E-Mail a.jo...@gis-systemhaus.de
Telefon +49 6201 503-59
Fax +49 6201 503-66
Gesellschaft für integrierte Systemplanung mbH
Geschäftsführer: Eckhard Haffmann, Alfred Gai, Bernd Heselmann
Sitz der Gesellschaft: Zeppelinstr. 11 - 91052 Erlangen
Amtsgericht Fürth/Bayern - Handelsregister-Nr. HRB 3435
sorry for messing up someones view
the same script file, but not the same method. var is a local variable
to the implicit run method, but then you even overwrite the run method.
So your code cannot work even if you removed the "def" in front of "def
var" and thus making it a value stored in the binding rather than a
local variable that is invisible in other methods.
bye blackdrag
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/