Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.57 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Load script from groovy script
  2. def method() {
  3.    println "test"
  4. }
  5.        
  6. method()
  7.        
  8. new GroovyShell().parse( new File( 'file1.groovy' ) ).with {
  9.   method()
  10. }
  11.        
  12. class File1 {
  13.   def method() {
  14.     println "test"
  15.   }
  16. }
  17.        
  18. def script = new GroovyScriptEngine( '.' ).with {
  19.   loadScriptByName( 'file1.groovy' )
  20. }
  21. this.metaClass.mixin script
  22.  
  23. method()
  24.        
  25. this.class.classLoader.parseClass("src/File1.groovy")
  26.  
  27. File1.method()
  28.  
  29. File1.newInstance().anotherMethod()
  30.        
  31. GroovyShell shell = new GroovyShell()
  32. def script = shell.parse(new File('/path/file1.groovy'))
  33. script.method()