Overview

Commons JEXL includes JSR-223 (javax.script) support. The binary jar includes the scripting factory and the services definition javax.script.ScriptEngineFactory, so no special configuration is needed.

Script engine support

The provided script engine implements the following (engineVersion="1.0"):

  • Language names: "JEXL", "Jexl", "jexl"
  • Extensions: ".jexl"
  • Mime-types: "application/x-jexl"
Script Engine versions from "2.0" also implement the following:
  • Language names: "JEXL2", "Jexl2", "jexl2"
  • Extensions: ".jexl2"
  • Mime-types: "application/x-jexl2"
The implementation adds an instance of JexlScriptObject to the engine context as the variable "JEXL". This gives scripts easier access to various items such as System.out and a logger.

Using the JSR-223 JEXL test application

The binary release includes a command-line application which can be used to exercise the JSR-223 script engine. For example:

java -cp commons-jexl-2.0.1.jar;commons-logging-1.1.1.jar[;bsf-api-3.0.jar] org.apache.commons.jexl2.scripting.Main script.jexl
If a single argument is provided, then that is assumed to be the name of a script file; otherwise, the application prompts for script input to be evaluated. In both cases, the variable "args" contains the command-line arguments. [Note that Java 1.5 does not include javax.script support; you will need to use the Apache BSF API jar as indicated.]

Using JEXL with JSR-223 on Java 1.5

In order to use JEXL via JSR-223 on Java 1.5, you need to add Apache BSF-API 3.0 jar to the classpath. JEXL also requires Commons Logging on the classpath.

Using JEXL with JSR-223 on Java 1.6+

JSR-223 support is included with Java 1.6+. JEXL requires Commons Logging, which needs to be included in the path.

JSR-223 support classes

The classes used to support JSR-223 scripting access are:

  • org.apache.commons.jexl2.scripting.JexlScriptEngineFactory - the factory
  • org.apache.commons.jexl2.scripting.JexlScriptEngine - the engine
  • org.apache.commons.jexl2.scripting.JexlScriptObject - class used to give scripts access to JEXL objects