Hi,

I have a problem with parsing my own DSL when using GroovyScriptEngine. Here’s 
the code:

class DslLoader {

 def load(String dsl) {
   CompilerConfiguration config = new 
CompilerConfiguration(CompilerConfiguration.DEFAULT)
   config.scriptBaseClass = MyBaseScript.class.name
   ClassLoader parentClassLoader = DslScriptLoader.classLoader
   GroovyClassLoader groovyClassLoader = new 
GroovyClassLoader(parentClassLoader, config)
   assert parentClassLoader.loadClass('groovy.lang.GroovyObject') != null // NO 
PROBLEMS HERE
   URL url = new File(‘path/to/my-dsl.jar').toURI().toURL()
   URL[] urlRoots = [url]
   GroovyScriptEngine engine = new GroovyScriptEngine(urlRoots, 
groovyClassLoader)
   assert engine.groovyClassLoader.loadClass('groovy.lang.GroovyObject') != 
null // NO PROBLEMS HERE
   Class clazz = engine.groovyClassLoader.parseClass(dsl, 'script’) // HERE I 
GET java.lang.ClassNotFoundException: groovy.lang.GroovyObject
   script = InvokerHelper.createScript(clazz, new Binding())
 }

}


As you can see from the comments, I’m able to load the class 
‘groovy.lang.GroovyObject’ when using the same class loader I pass to 
GroovyScriptEngine. But when I call parseClass(), my application fails with a 

java.lang.ClassNotFoundException: groovy.lang.GroovyObject

The code above is part of an OSGI bundle which is deployed to a container. 
groovy-all.jar is on the bundle class path: 

Bundle-ClassPath: .,META -INF/lib/groovy-all-2.4.4.jar 

I don’t understand why GroovyScriptEngine is not able to load Groovy’s own 
classes although the passed class loader can do it. Am I overlooking something? 
Do you have an idea what is wrong?

Thanks in advance,
Michael

Reply via email to