Fwd: how to import a groovy class in a Jgrass scrpit

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Fwd: how to import a groovy class in a Jgrass scrpit

Emanuele Cordano

Dear all, 

I'm trying to crete groovy class in external files and then import them in a jgrass groovy script. I looked for some examples on line (include the website of groovy) and I found an interested example like this one: 
then I repeat this in a Jconsole but it did not work. 
I simplified the example, I put two files in a same folder: readData.groovy and valueAdd.groovy . 
The first one is: 

class readData {


 double a_valore=5.3;
 int b_valore=7;
 
 void main(def arg) {
 
  def le=new readData ()
println le.d_valore
 }
}

and the second one: 


import readData.*

//def RE=new readData()
println readData.b_valore 


Then I run the second one and I obtain  the following message :

-------------------------------- Compiling... ---------------------------------
valueAdd.groovy
valueAdd.groovy - 0 model/s compiled, total compilation time: 34 ms

-------------------------------------------------------------------------------
GroovyShell, Version 1.5.5, http://groovy.codehaus.org 
------------------------------ Running model... -------------------------------
No such property: readData for class: Script1
No such property: readData for class: Script1

Total run time: 205 ms 
 
If I run the following script in one file: 

class readData {


 double a_valore=5.3;
 int b_valore=7;
 
 void main(def arg) {
 
  def le=new readData ()
println le.d_valore
 }
}

def le=new readData ()
println le.b_valore

It works and I obtained as expected :
JGrass 2 Console ML (Model Language) Compiler, Version 1.0.0.832, for i386
Copyright (C)
HydroloGIS - www.hydrologis.com,
-------------------------------- Compiling... ---------------------------------
readData.groovy
readData.groovy - 0 model/s compiled, total compilation time: 250 ms

-------------------------------------------------------------------------------
GroovyShell, Version 1.5.5, http://groovy.codehaus.org 
------------------------------ Running model... -------------------------------
7

Total run time: 443 ms

I made several trials but without any success. How can I import a groovy class from an external file to groovy Jgrass Script? 

Thank you very much 

Emanuele Cordano




_______________________________________________
JGrass-users mailing list
[hidden email]
https://dev.fsc.bz.it/cgi-bin/mailman/listinfo/jgrass-users