Apache Commons logo Apache Commons JEXL

Overview

Apache 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 "3.0" also implement the following:
  • Language names: "JEXL2", "Jexl2", "jexl2", "JEXL3", "Jexl3", "jexl3"
  • Extensions: ".jexl2", ".jexl3"
  • Mime-types: "application/x-jexl2", "application/x-jexl3"
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-3.1.jar;commons-logging-1.2.jar
            org.apache.commons.jexl3.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.

JSR-223 support classes

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

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