//////////////////////////////////////////

  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.

//////////////////////////////////////////

[[jsr223]]
= JSR 223 javax.script API

WARNING: JSR-223 is a standard API for calling scripting frameworks in Java. It is available since Java 6 and aims at
providing a common framework for calling multiple languages from Java. Groovy provides its own richer integration mechanisms,
and if you don't plan to use multiple languages in the same application, it is recommended that you use the Groovy
integration mechanisms instead of the limited JSR-223 API.

Here is how you need to initialize the JSR-223 engine to talk to Groovy from Java:

[source,java]
--------------------------------------------------------------------------------------
include::{rootProjectDir}/subprojects/groovy-jsr223/src/spec/test/JSR223SpecTest.java[tags=jsr223_imports,indent=0]
...
include::{rootProjectDir}/subprojects/groovy-jsr223/src/spec/test/JSR223SpecTest.java[tags=jsr223_init,indent=0]
--------------------------------------------------------------------------------------

Then you can execute Groovy scripts easily:

[source,java]
----
include::{rootProjectDir}/subprojects/groovy-jsr223/src/spec/test/JSR223SpecTest.java[tags=jsr223_basic,indent=0]
----

It is also possible to share variables:

[source,java]
----
include::{rootProjectDir}/subprojects/groovy-jsr223/src/spec/test/JSR223SpecTest.java[tags=jsr223_variables,indent=0]
----

This next example illustrates calling an invokable function:

[source,java]
-------------------------------------------------------------------------------
import javax.script.Invocable;
...
include::{rootProjectDir}/subprojects/groovy-jsr223/src/spec/test/JSR223SpecTest.java[tags=jsr223_invocable,indent=0]
-------------------------------------------------------------------------------

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
context of the name `#jsr223.groovy.engine.keep.globals` with a
String being `phantom` to use phantom references, `weak` to use weak
references or `soft` to use soft references - casing is ignored. Any
other string will cause the use of hard references.

