No suitable ClassLoader found for grab

1,050 views
Skip to first unread message

Bill Turner

unread,
Apr 25, 2014, 4:38:05 PM4/25/14
to groo...@googlegroups.com
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.

What seems promising at present is described at http://stackoverflow.com/questions/9805983/grab-annotation-working-from-jsr-223, though it seems this would be a lot of ceremony to do what I wish and I am not sure I really understand how I could use the reply in my context.

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
@Grapes([
@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"


init()
println this.toString()

void init() {
this.consoleOutput = true
    
//    println this.toString()
}

String toString() {
return "callee [name=" + name + ", target=" + target + ", consoleOutput=" + consoleOutput + ", version=" + version + "]";
}


pair.prog...@gmail.com

unread,
Mar 10, 2017, 12:30:24 PM3/10/17
to Groovy Users of Minnesota
Hello, Bill

Did you find a way to fix this? If yes, can you provide suggestion on how to fix this?

Thank you.
Reply all
Reply to author
Forward
0 new messages