开发者

How to run a set of dependent groovy scripts without compilation?

开发者 https://www.devze.com 2023-02-25 12:59 出处:网络
I\'ve got a set of groovy scripts (or should I say a groovy app) which has hierarchical java alike package structure and script names the same as class names. All of them are called from the main scri

I've got a set of groovy scripts (or should I say a groovy app) which has hierarchical java alike package structure and script names the same as class names. All of them are called from the main script (like a java class with main method). I need to call just that particular main script and get all other scripts executed in sequ开发者_运维百科ence when needed (or loaded and executed).

Practically, this can be acieved by having all scripts compiled and .class files obtained and put into classpath while running the main script, but that's quite redundant for a scripting (the idea is to have it working without compilation, even though groovy will do it somwhere behind the scene)

How can I achieve it?


Groovy can be used in a scripting environment quite easily - no compile step required. Read this:

http://groovy.codehaus.org/Running

You can write your usual main method etc. and call it like this,

groovy -cp foo/ foo/MyScript.groovy [arguments]

Or if you're in a *nix environment you can give it a shebang like so,

#!/usr/bin/env groovy
println("Hello world")
for (a in this.args) {
  println("Argument: " + a)
}

and run it using ./fileName (provided you've marked it as executable)

0

精彩评论

暂无评论...
验证码 换一张
取 消