JSR-223 and Groovy
I have a need for a scripting language in my Java application.
I'm leaning toward开发者_运维问答s Groovy as the tooling and language seem the best fit for the job.
My confusion comes from where the whole JSR-223 fits into all this. Should I care about using the specific JSR-223 interfaces when creating the engine?
For example, we have a need to remotely store our scripts, and be able to trigger our app to re-load them on demand. The GroovyScriptEngine seems to be exactly what we would want to use.
However, this page talks about creating a Groovy engine according to the JSR-223 spec. This interface is much more limited, and lacks the functionality that we need, without building additional code.
How does the JSR-223 fit into all this? Should I care about using the JSR-223 interfaces? Why?
From the Groovy documentation on JSR 223:
Groovy has many mechanisms for integration with Java, some of which provider richer options than available with JSR 223 (e.g. greater configurability and more security control). JSR 223 is recommended when you need to keep the choice of language used flexible and you don't require integration mechanisms not supported by JSR-223.
Are you going to plug other languages in to your framework?
If so, then I guess you're going to need the JSR-223 stuff..
If not, and you only want to plug Groovy in, then I'd side-step this and go the more direct route...
If you wonder why the script engine is not found by the ScriptEngineManager. The reason is that the support for JSR 223 is droped in version 2.x of Groovy.
As documented on this page support for JSR 233 added on version 1.6. The code for the integration is located in the package org.codehaus.groovy.jsr223.
In version 2.x it seems that this package is removed.
精彩评论