Sono in ritardo ma. Questo è il modo in cui abbiamo raggiunto ciò che stavi chiedendo. Così, ho un file1.gsh in questo modo:
File1:
println("this is a test script")
def Sometask(param1, param2, param3)
{
retry(3){
try{
///some code that uses the param
}
catch (error){
println("Exception throw, will retry...")
sleep 30
errorHandler.call(error)
}
}
}
return this;
E in un altro file, queste funzioni sono accessibili istanziando prima. Quindi in file2.
File2:
def somename
somename = load 'path/to/file1.groovy'
//the you can call the function in file1 as
somename.Sometask(param1, param2, param3)
Ho usato il metaClass.mixin funziona perfettamente. Grazie – ptomasroos
Un'altra domanda, una breve correlata. Se voglio eseguire uno script come previsto, lo script non è di classe. Non invocare un metodo. Lika esegue o esegue il metodo. – ptomasroos
Probabilmente vuoi [GroovyShell.evaluate] (http://groovy.codehaus.org/api/groovy/lang/GroovyShell.html#evaluate (java.io.File)) –