static void m1() {
println 'One'
}
One.m1()
-- Cédric Champeau SpringSource - A Division Of VMware http://www.springsource.com/ http://twitter.com/CedricChampeau
Am 11.05.2012 16:41, schrieb Mohamed Seifeddine:Someone who needed that implemented it for his scripts, but without making it public and it never found its way into the compiler. Many use now mixin instead I guess
I found this old thread ( from 2006! )
http://groovy.329449.n5.nabble.com/Scripting-philosophy-was-calling-functions-in-other-groovy-scripts-td331530.html
Jochen suggesting back then that this could easily be added, with
something similar to :
import inlined "Test0.groovy"
Test0.methodOne()
What happened with this suggestion Jochen?
Does your second script contain a package declaration? It should.
include 'bar.groovy'
methodFromBar('hello') // this works because
methodFromBar('hello') is equivalent to
binding['methodFromBar'].call('hello')
void methodFromBar(arg) { println arg }
void include(filename) {
def scriptClass = new GroovyShell().parse(new
File('bar.groovy')).class
def obj = scriptClass.newInstance()
scriptClass.methods.findAll { !it.isSynthetic() }.each {
binding[it.name] = new
org.codehaus.groovy.runtime.MethodClosure(obj, it.name)
}
}
And you run your script from the top-level directory, right?
$ cat foo/One.groovy
package foo
def testMe() { println "foo.One.testMe" }
$cat foo/Run.groovy
package foo
new foo.One().testMe()
$groovy -cp . foo/Run.groovy
foo.One.testMe