groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guillaume Laforge <glafo...@gmail.com>
Subject Re: Groovy has: Add Imports Transparently to Scripts with ImportCustomizer; Is there a Java equivalent?
Date Mon, 20 Jul 2015 12:21:27 GMT
Agreed with Cédric, as JSR-223 is really too brained-down to be really
useful.

It's still however possible to cast the Groovy javax script engine to its
concrete implementation class, and then you can access the underlying
GroovyClassLoader used, and set the CompilerConfiguration to what you want.
But you're now tied to the specifics of the Groovy implementation of
JSR-233.
I had a customer that really wanted to use JSR-223/javax.script, but had to
worrkound that way to such things as customize the imports and more. They
had come up with this solution.

On Mon, Jul 20, 2015 at 2:13 PM, Cédric Champeau <cedric.champeau@gmail.com>
wrote:

> No. That's what one of the limitations we fight against in JSR-223. It is
> very limited, and doesn't support any kind of configuration of the engine.
> In other words, if you don't need to rely on the limited JSR-223 api,
> better use the Groovy specific engine instead.
>
> 2015-07-20 13:54 GMT+02:00 Steve Amerige <Steve.Amerige@sas.com>:
>
>>  I received the question:
>>
>> *org.codehaus.groovy *implementation of Groovy (groovy-all) provides a
>> mechanism to set imports when evaluating Groovy code via *
>> CompilerConfiguration *and *ImportCustomizer*. I don't see the
>> equivalent in *javax.script *in *ScriptEngine*/*ScriptContext*. Is there
>> a way I can add (implicit) imports in *javax.script*, perhaps by setting
>> a *ScriptContext *attribute?
>>
>>
>> Can anyone throw any light on this?  MrHaki has a nice article
>> <http://mrhaki.blogspot.com/2011/06/groovy-goodness-add-imports.html?_sm_au_=iVV4skZWKl7N5q75>
>> on the Groovy side.
>>
>> Thanks,
>> Steve Amerige
>>  Principal Software Developer, Fraud and Compliance Solutions Development
>> SAS Institute, 100 SAS Campus Dr, Room U3050, Cary, NC 27513-8617
>>
>>
>>
>>
>>
>


-- 
Guillaume Laforge
Groovy Project Manager
Product Ninja & Advocate at Restlet <http://restlet.com>

Blog: http://glaforge.appspot.com/
Social: @glaforge <http://twitter.com/glaforge> / Google+
<https://plus.google.com/u/0/114130972232398734985/posts>

Mime
View raw message