How do I do that via the javax.script API?

Even if this is possible via the javax.script API, chances are that a user 
wishes to ad-hoc add another import, but as they are forgotten between script 
invocations, it makes it hard to use Groovy to interactively create, say a 
Swing or JavaFX UI one line at a time. With BeanShell, the user can add the 
needed imports, execute that "script" and then continue to refer to the 
imported classes in the following script invocations. Making Groovy remember 
imports would make it behave in as nice fashion as the new JShell tool in Java 
9. JShell unfortunately cannot run embedded via the javax.script API :-(

Regards
/David

> On 8 Feb 2018, at 21:34, eric.mil...@thomsonreuters.com wrote:
> 
> You can add all the imports you want to your compiler configuration and they 
> will be consistently available for all scripts.
>  
> From: David Ekholm [mailto:da...@jalbum.net <mailto:da...@jalbum.net>] 
> Sent: Thursday, February 08, 2018 2:12 PM
> To: dev@groovy.apache.org <mailto:dev@groovy.apache.org>
> Subject: Remembering imports between script invocations 
>  
> We're considering supporting Groovy as an additional scripting language to 
> our web gallery software jAlbum (http://jalbum.net 
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__jalbum.net&d=DwMFAg&c=4ZIZThykDLcoWk-GVjSLmy8-1Cr1I4FWIvbLFebwKgY&r=tPJuIuL_GkTEazjQW7vvl7mNWVGXn3yJD5LGBHYYHww&m=39n_uU4e7-n_s_WwrNC_8tQYLfhWKgmT_dDWwJw8ctA&s=jGwsu2zf5Pm3kG3GKLFFxalyi30aoXq_-izsMrEy_iQ&e=>),
>  but one aspect bugs me: It doesn't seem like import statements are 
> remembered between script invocations. This makes it far harder to use Groovy 
> to prototype UIs within jAlbum's scripting console than for instance 
> BeanShell (using the javax.script API). We currently support the slow 
> BeanShell scripting language and JavaScript. BeanShell behaves well in this 
> regard, remembering earlier imported packages between script invocations. Can 
> this be added to Groovy or is there some API flag we can set?
>  
> Regards
> /David, jAlbum founder and client lead developer.

Reply via email to