Re: [Objectscript-users] using mountJarFile
Brought to you by:
rob_d_clark
From: Rob C. <ro...@ti...> - 2005-10-07 18:33:31
|
Hmm... I suspect it will depend on which classloader loads oscript.OscriptInterpreter... if you manage to get the AntClassloader2 to load the ObjectScript classes, then there is probably nothing more to do. Everything goes thru oscript.compiler.CompilerClassLoader.forName(), so you could probably put some code in there to try an alternate classloader. I actually probably add an API to somehow register an alternative ClassLoader anyways, since it seems to be required to work around the way eclipse's classloaders perform additional access restrictions. (Ie. a plugin using ObjectScript would need to provide a class loader so that ObjectScript could load classes defined by that plugin.) And beyond that, there is the declareJavaPackage() hack, since there is no java API to discover java packages of java classes that have not yet been loaded. -- Rob On Oct 7, 2005, at 11:10 AM, Lysander David wrote: > Thanks for the quick response. > > Since that doesn't modify the classpath for > the classloader, is there an accepted way > to set up a new classloader with a classpath > defined at runtime. As quick hack, I've > compiled the AntClassloader2 > and was able to load a class from a runtime-defined > classpath in plain java. If that is acceptable within > objectscript, > how would it be possible to make the JavaPackage > object aware of the AntClasloader2 ? > > Thanks again, > Lysander > > > > --- Rob Clark <ro...@ti...> wrote: > > >> A couple things... >> >> first, mounting it just makes it available within >> the abstract >> filesystem. So you could then, for example, use >> pkg.fs.File() to >> access files within the jar (ie >> "/jar/xstream-SNAPSHOT/foo/bar.os"). >> And of course if you have script files within the >> jar, they could be >> imported or accessed thru pkg. But it does not add >> the jar to the >> classpath. (Although I think this could be >> implemented, and it is an >> interesting idea... I'll have to look into it.) >> >> second, you will probably need to use >> pkg.system.declareJavaPackage() >> for any java package that is first accessed from the >> script >> environment, otherwise the JavaPackage object has no >> way to know that >> the package actually exists, and so it will throw a >> >> NoSuchMemberException. >> >> >> >> On Oct 6, 2005, at 6:10 PM, Lysander David wrote: >> >> >>> Hi, >>> >>> How does one use pkg.system.mountJarFile ? >>> >>> I am attempting to instantiate an object of >>> class com.thoughtworks.xstream.XStream. >>> The class exists in this jar: >>> >>> xstream-SNAPSHOT.jar >>> >>> When I execute these commands: >>> >>> import "reflection.os"; >>> var file = new pkg.fs.File ( >>> >> "xstream-SNAPSHOT.jar" ); >> >>> pkg.system.mountJarFile ( file ); >>> var com = new JavaPackage ("com" ); >>> var x = new com.thoughtworks.xstream.XStream(); >>> >>> >>> I get this error: >>> >>> oscript.exceptions.PackagedScriptObjectException: >>> NoSuchMemberException: no such member: >>> >> JavaPackage: >> >>> thoughtworks >>> >>> >>> What must be done to mount xstream-SNAPSHOT.jar >>> and instantiate com.thoughtworks.xstream.XStream ? >>> >>> Thanks >>> >>> >> >> -- Rob >> >> ____________________ >> CONTACT INFORMATION: >> email: ro...@ti... >> IM: rob@sandjabber >> >> >> >> >> > > -- Rob ____________________ CONTACT INFORMATION: email: ro...@ti... IM: rob@sandjabber desk: 1 858 552 2946 cell: 1 619 300 9661 |