简体   繁体   English

JSR-223和Groovy

[英]JSR-223 and Groovy

I have a need for a scripting language in my Java application. 我的Java应用程序中需要脚本语言。

I'm leaning towards Groovy as the tooling and language seem the best fit for the job. 我倾向于Groovy,因为工具和语言似乎最适合这份工作。

My confusion comes from where the whole JSR-223 fits into all this. 我的困惑来自整个JSR-223是否适合所有这些。 Should I care about using the specific JSR-223 interfaces when creating the engine? 创建引擎时,我应该考虑使用特定的JSR-223接口吗?

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. GroovyScriptEngine似乎正是我们想要使用的。

However, this page talks about creating a Groovy engine according to the JSR-223 spec. 但是, 页面讨论根据JSR-223规范创建Groovy引擎。 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? JSR-223如何适合所有这些? Should I care about using the JSR-223 interfaces? 我应该考虑使用JSR-223接口吗? Why? 为什么?

From the Groovy documentation on JSR 223 : 有关JSR 223Groovy文档中

Groovy has many mechanisms for integration with Java, some of which provider richer options than available with JSR 223 (eg greater configurability and more security control). Groovy有许多与Java集成的机制,其中一些提供了比JSR 223可用的提供程序更丰富的选项(例如,更好的可配置性和更多的安全性控制)。 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. 当您需要保持灵活使用的语言选择并且不需要不需要JSR-223支持的集成机制时,建议使用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.. 如果是这样,那么我想您将需要JSR-223材料。

If not, and you only want to plug Groovy in, then I'd side-step this and go the more direct route... 如果不是这样,而您只想插入Groovy,那么我会回避并走更直接的路线...

If you wonder why the script engine is not found by the ScriptEngineManager. 如果您想知道为什么ScriptEngineManager找不到脚本引擎。 The reason is that the support for JSR 223 is droped in version 2.x of Groovy. 原因是Groovy的2.x版本中不再支持JSR 223。

As documented on this page support for JSR 233 added on version 1.6. 本页所述 ,在版本1.6中添加了对JSR 233的支持。 The code for the integration is located in the package org.codehaus.groovy.jsr223. 集成代码位于包org.codehaus.groovy.jsr223中。

In version 2.x it seems that this package is removed. 在2.x版中,似乎已删除了此软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM