Skip to content

Instantly share code, notes, and snippets.

@aalmiray
Last active December 21, 2016 04:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aalmiray/5395913 to your computer and use it in GitHub Desktop.
Save aalmiray/5395913 to your computer and use it in GitHub Desktop.
// zt.Engine.java
package zt;
public interface Engine {
void start();
void stop();
}
// zt.EngineScript.java
package zt;
import groovy.lang.Script;
public abstract class EngineScript extends Script implements Engine {
}
// engine.groovy
void start(){
println "Start the engines!"
}
void stop(){
println "Stop at once!"
}
this
// runner.groovy
import zt.*
import org.codehaus.groovy.control.CompilerConfiguration
// create a configuration
def config = new CompilerConfiguration()
// tweak the configuration
config.scriptBaseClass = 'zt.EngineScript'
// run your script
def shell = new GroovyShell(config)
engineScript = shell.evaluate(new File('engine.groovy').text)
assert engineScript instanceof Engine
engineScript.start()
engineScript.stop()
// run it with
javac -d classes -cp $GROOVY_HOME/embeddable/groovy-all-<version>.jar zt/*
groovy -cp classes runner.groovy
@sunxboy
Copy link

sunxboy commented Apr 17, 2013

good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment