jastrachan | 6 Apr 16:31 2004
Picon

Re: [Newbie] Classloading Problem

One quick thought to see if it helps - you could try calling

groovy.lang.MetaClass.useReflection(true)

before running your script to see if it helps? Basically the main  
change in b4 was to use bytecode-generated alternatives to reflection.  
I wonder if re-enabling reflection fixes your issue while we figure out  
the problem.

On 6 Apr 2004, at 15:07, ldewavrin@... wrote:

>
> Hi,
> I am trying to execute a groovy script from a Java class and
> I get a NoClassDefFoundError. The way I load the groovy script used to
> work with groovy-1.0-beta3
> but does not work anymore with groovy-1.0-beta4. Actually,
> before parsing the groovy script I set the GroovyClasserloader's  
> parent to
> a URLClassLoader.
> In the latter, there are classes that will be invoked in my groovy  
> script.
> The groovy and asm jars are in my system classpath but not the jar  
> files
> in the URLClassLoader.
>
> Here's what I have done:
>             File weblogicjar = new File(genbean.getWlshome() +
> File.separator+"server/lib/weblogic.jar");
>             File wlssecurityjar= new File("lib/wlssecurity.jar");
>             if (weblogicjar.exists()) System.out.println("Weblogic jar
> found");
>             if (wlssecurityjar.exists())  
> System.out.println("Wlssecurity
> jar found");
>             URL[] listurl =  
> {weblogicjar.toURL(),wlssecurityjar.toURL()};
>             URLClassLoader urlc = new URLClassLoader(listurl);
>             Thread.currentThread().setContextClassLoader(urlc);
>             GroovyClassLoader loader = new GroovyClassLoader(urlc);
>             Class groovyClass = loader.parseClass(new
> File(SERVER_GROOVY_SCRIPT));
>             // lets call some method on an instance
>             Object[] args = {genbean, serverbean};
>             GroovyObject groovyObject = (GroovyObject)
> groovyClass.newInstance();
>             groovyObject.invokeMethod("init", args);
>             ...
>
> And what I get on standard ( and error ) output:
>
> Weblogic jar found
> Wlssecurity jar found
>
> java.lang.NoClassDefFoundError: SecurityHelper
> at
> gjdk.SecurityHelper_GroovyReflector.invoke(SecurityHelper_GroovyReflect 
> or.java)
> 	at groovy.lang.MetaMethod.invoke(MetaMethod.java:108)
> 	at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:846)
> 	at groovy.lang.MetaClass.invokeStaticMethod(MetaClass.java:329)
> 	at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:124)
> 	at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.ja 
> va:101)
>
> SecurityHelper is a class which is my wlssecurity.jar file.
>
> This code works with beta3 and does not work with beta4.
>
> Am i doing the wrong way ?
>
>
> Luc
> _______________________________________________
> groovy-user mailing list
> groovy-user@...
> http://lists.codehaus.org/mailman/listinfo/groovy-user
>
>

James
-------
http://radio.weblogs.com/0112098/

Gmane