Message-ID: <862492923.774560.1386284331870.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_774559_381326453.1386284331869" ------=_Part_774559_381326453.1386284331869 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Java 6 includes built-in support for JSR 223= : Scripting for the Java Platform API classes. This framework can be us= ed to host Script Engines in Java Applications. Numerous Scripting engines = are available.
Here is how you can use JSR 223 to talk to Groovy from Java:
The output is:
To make this example work, if you're running Groovy 1.5.x, add
ovy-engine.jar from https://scripting.dev.java.net/ to=
your CLASSPATH and run this program using Java 6. But since Groovy 1.6, Gr=
oovy already contains the groovy scripting engine compliant with JSR-223.=
This next example illustrates calling an invokable function:
And when run, results in:
Groovy has many mechanisms for integration with Java, some of which prov= ider richer options than available with JSR 223 (e.g. greater configurabili= ty 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 mec= hanisms not supported by JSR-223.
The engine keeps per default hard references to the script functions. To= change this you should set a engine level scoped attribute to the script c= ontext of the name "#jsr223.groovy.engine.keep.globals" = with a String being "phantom" to use phantom references, "we= ak" to use weak references or "soft" to use soft references = - casing is ignored. Any other string will cause the use of hard references= .
See also: JSR-223 access to other JVM languages