-
1. Re: Javassist and JavaWebStart
ghawkins Feb 2, 2004 8:24 AM (in response to jblumenkrantz)I have the same problem as jblumenkrantz, and don't want to give up on Javassist. Does anyone have any thoughts?
-
2. Re: Javassist and JavaWebStart
chiba Feb 3, 2004 7:59 AM (in response to jblumenkrantz)Can you modiy as following and try again?
// in javassist/ClassPoolTail.java,
final class SystemClassPath implements ClassPath {
Class thisClass;
SystemClassPath() {
// old: thisClass = java.lang.Object.class;
thisClass = this.getClass();
}
:
} -
3. Re: Javassist and JavaWebStart
jblumenkrantz Feb 3, 2004 8:57 AM (in response to jblumenkrantz)After making that change, ClassPool.get() seems to be working fine, and I'm able to generate my custom subclass, but I'm now getting an error when I call myNewCtClass.toClass() after I'm done with the class generation. The stack trace is as follows, and the class that is not found is identical to the one that failed originally in ClassPool.get(). Might I need to make a similar fix elsewhere?
Thanks a lot
-Jason
java.lang.NoClassDefFoundError: mypackage/cell/Cell
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at javassist.ClassPool$LocalClassLoader.loadClass(ClassPool.java:365)
at javassist.ClassPool.writeAsClass(ClassPool.java:427)
at javassist.CtClass.toClass(CtClass.java:770) -
4. Re: Javassist and JavaWebStart
bill.burke Feb 3, 2004 2:12 PM (in response to jblumenkrantz)Looks like a classloader problem. Where is mypackage/cell/Cell? Is it in the System classpath? Or is it loaded by some sub-classloader?
The CtClas.toClass() method uses a custom embedded ClassLoader in which the parent CL is the System classloader.
My bet is that you will have to create is a subclass of ClassLoader in which you expose a loadClassFromBytes(String name, byte[] bytes) this method would have to call defineClass. The parent classloader of this classloader would have to be:
Thread.currentThread().getContextClassLoader()
or
MyPackage.cell.Cell.class.getClassLoader();
Am I making sense?
bill -
5. Re: Javassist and JavaWebStart
ghawkins Feb 3, 2004 4:29 PM (in response to jblumenkrantz)That did the trick, thanks a lot! jblumekrantz, did that solve your problem too?
-
6. Re: Javassist and JavaWebStart
jblumenkrantz Feb 3, 2004 4:39 PM (in response to jblumenkrantz)I got it working fine if I replaced the LocalClassLoader constructor as follows:
public LocalClassLoader() {
super(Thread.currentThread().getContextClassLoader());
}
WebStart is using a custom JNLPClassLoader that is apparently getting bypassed otherwise. Ideally I'd create another constructor for ClassPool to define the LocalClassLoader's parent class loader, but this does the trick for now.
Thanks
-Jason