I've really researched this, but have not hit on the answer. I have a target script that I wish to call from another script. The target script uses Grab to pull in necessary resources. I can run the target standalone just fine. However, when calling it from another script I get the infamous No suitable ClassLoader found for grab error. There seems to be a lot of discussion of this on the web, though none of the solutions have worked for me thus far. For example, one suggestion is to include
@GrabConfig( systemClassLoader=true ). This only causes the items imported to get flagged with
Groovy:unable to resolve class org.apache.commons.cli.Option.
I am at present trying to run these out of Eclipse, though the same error is generated when launching a shell script (cygwin).
Groovy Version: 2.2.1 JVM: 1.7.0_25 Vendor: Oracle Corporation OS: Windows 7 Eclipse (Juno) with GGTS
Here are the sample caller and callee scripts:
// caller
Binding binding = new Binding()
binding.setVariable("name", "Pooh")
binding.setVariable("target", "May")
new callee(binding).run()
// callee
@Grab(group='org.mod4j.org.apache.commons', module='cli', version='1.0.0')
import org.apache.commons.cli.Option
import org.apache.commons.cli.ParseException
import groovy.transform.Field
@Field String name = "Bill"
@Field String target = "test"
@Field Boolean consoleOutput=true // write output to console
@Field def version = "0.1"
this.consoleOutput = true
// println this.toString()
return "callee [name=" + name + ", target=" + target + ", consoleOutput=" + consoleOutput + ", version=" + version + "]";