You've got two separate issues to deal with, neither addressed by the 
current javax.script API.

The first is managing the classpath used the classloader, along with the 
related problem of getting the bytecode itself.  IFCX Wings uses Ivy for 
getting the dependencies and uses a hack that relies on being able to 
manipulate the list of JAR files in a URLClassLoader.

http://ifcx.svn.sourceforge.net/viewvc/ifcx/Wings/trunk/OpenOffice/WingsEval.groovy?revision=175&view=markup#l_2351

The second, and the one that I think you refer to, is that you may want 
to tweak the classes and/or package that a language imports by default.

A way to do that would be to implement a proxy ScriptEngine that 
modifies the script before processing by the existing engine.  Of course 
what to prepend would depend on the particular language implemented by 
the engine.  Groovy's shell does that sort of thing.

But because the preprocessing is likely to be so language specific and 
most script engines are OSS, you might find it more convenient to just 
modify the engines you care about and give them a different name.  If 
you look in most of the implementations you'll find a method that does 
the "get script source" thing, that would be place to subclass and do 
the tweaking (with ScriptContext API or such if you like).

A related idea that I've been intending to implement for a long while 
now, is import processing (with or without annotations) that combines 
both the namespace and dependency + classpath loading.

Groovy is part of the way there with @Grab, and Wings has "uses".

Jim

Greg Brown wrote:

> Hi all,
> 
> Is there a way to programmatically import a class or package into a
> script engine such that the script itself does not need to? Basically,
> I want to pre-populate the script's namespace with the imports. I
> looked for an "importClass()" or "importPackage()" method in the
> ScriptEngine and ScriptEngineManager classes, but I couldn't find one.
> Any suggestions?
> 
> Thanks,
> Greg Brown


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to jvm-languages@googlegroups.com
To unsubscribe from this group, send email to 
jvm-languages+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to