Subj : Re: can a scope (ScriptableObject) be serialized to disk in Rhino? To : netscape.public.mozilla.jseng From : Igor Bukanov Date : Tue Jan 25 2005 06:53 pm Mark Turansky wrote: > when attempting to save (via ObjectOutputStream) a scope, I am getting this > exception: > > java.io.NotSerializableException: > org.mozilla.javascript.LazilyLoadedCtor Use ScriptableOutputStream and ScriptableInputStream, http://www.mozilla.org/rhino/apidocs/index.html, to read/write your scope object. > > I am growing a library of js code which I know I can easily include in all > my scripts via a shared scope. > > Instead, though, of executing all the scripts in the library against the > shared scope during every invocation of my script runner, I'd like to be > able to execute the library once, save that shared scope to disk, and > retrieve it as the shared scope in my javascript runtime at startup. > > Is this possible given the exception above? By default Rhino compiles scripts to JVM classes so unless you make the generated classes available for the new JVM, you would not be able to read them. You can force the interpreted mode which would generate fully serializable objects, but that is much slower. Instead of serialization I would suggest to simply precompile scripts and initialize the scope at run time using the compiled classes, see http://www.mozilla.org/rhino/jsc.html and http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/optimizer/ClassCompiler.html Regards, Igor .