This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: Making Serializable Classes
- From: Per Bothner <per at bothner dot com>
- To: Ranjan Bagchi <ranjan dot bagchi at frotz dot com>
- Cc: kawa at sources dot redhat dot com
- Date: Sat, 26 Jan 2002 23:40:55 -0800
- Subject: Re: Making Serializable Classes
- References: <1011816896.6779.ezmlm@sources.redhat.com> <3C5386CF.9F7AE012@frotz.com>
Ranjan Bagchi wrote:
>
> I was experimenting with creating classes in Kawa, and was curious about making
> Serializable classes.
> ...
> What didn't work fine was deserializing the object: I get the following error
> java.lang.ClassNotFoundException: MyClass
> at java.net.URLClassLoader$1.run(URLClassLoader.java:201)
The problem is that dynamically generated classes are loaded from
ArrayClassLoaders, and a new ArrayCloassLoader instance is created
for each itme an expression is evaluated. This works find for normal
Scheme code, but not for classes that must be referenced by name.
The fix to change Kawa so it uses a shared ArrayClassLoader (perhaps
one per top-level Environment), but it gets a little trickier because
we want to garbage collect anonyous temporary classes.
A work-around is to wrap your entire program in a (begin ...).
That seems to work.
A better solution is to compile any code that uses define-class:
java kawa.repl -C MyModule.scm)
java kawa.repl -e '(load <MyModule>)' --
That makes MyClass visble to the default system class loader.
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/