JCR 223 在各种语言的实现

麦地兜兜 发布于 2012/12/15 04:00
阅读 495
收藏 0

码上生花,ECharts 作品展示赛正式启动!>>>

The J2EE platform implements the java.script APIs, which allow to integrate script engines that comply with JSR 223.

An overview of some JSR 223 compatible scripting languages is presented below: 


(JSR 223 implementation Rhino 1.6R7) -http://www.mozilla.org/rhino/

JavaScript is a dynamic scripting language supporting prototype based object construction. The basic syntax is intentionally similar to both Java and C++ to reduce the number of new concepts required to learn the language. Language constructs, such as if statements, for and while loops, and switch and try ... catch blocks function the same as in these languages (or nearly so.)

JavaScript can function as both a procedural and an object oriented language. Objects are created programmatically in JavaScript, by attaching methods and properties to otherwise empty objects at run time, as opposed to the syntactic class definitions common in compiled languages like C++ and Java. Once an object has been constructed it can be used as a blueprint (or prototype) for creating similar objects.

JavaScript's dynamic capabilities include runtime object construction, variable parameter lists, function variables, dynamic script creation (via eval), object introspection (via for ... in), and source code recovery (JavaScript programs can decompile function bodies back into their source text)

Intrinsic objects are Number, String, Boolean, Date, RegExp, and Math.


Rhino is available under open source licenses. The majority of the source code for Rhino is available under aMPL 1.1/GPL 2.0 license. 


(JSR 223 implementation Jawk 0.14) -http://jawk.sourceforge.net/

Jawk interprets AWK scripts in Java. This is a full implementation of AWK, which includes:

  • An intuitive text processing paradigm, tightly integrated with regular expressions.
  • Functions with local, static scoping.
  • Scalar and associative array (map) variables.
  • Weakly typed variables for greatest flexibility with automatic string/number conversion.
  • Powerful IPC constructs similar to those used by most UNIX shells (pipes and IO redirect).
  • Highly intuitive error diagnostics.

Jawk also offers the following features which the original AWK does not provide:

  • Output to a post-compiled, pre-interpreted format for both elimination of the compilation step and obfuscation of Jawk scripts.
  • Text dumps of abstract syntax tree and intermediate code representation (tuples).
  • Maintenance of associative arrays in key-sorted order.
  • Error detection for printf/sprintf format parameters (via the -r argument).
  • Compilation of scripts to bytecode executable on any modern JVM.
  • An opt-in, flexible extension facility with event blocking capabilities (in interpreted mode, only).

Jawk is available under open source licenses.


(JSR 223 implementation FreeMarker 2.3.11) - http://freemarker.sourceforge.net/

FreeMarker is a "template engine"; a generic tool to generate text output (anything from HTML to autogenerated source code) based on templates. It's a Java package, a class library for Java programmers. It's not an application for end-users in itself, but something that programmers can embed into their products.

FreeMarker is designed to be practical for the generation of HTML Web pages, particularly by servlet-based applications following the MVC(Model View Controller) pattern. The idea behind using the MVC pattern for dynamic Web pages is that you separate the designers (HTML authors) from the programmers. Everybody works on what they are good at. Designers can change the appearance of a page without programmers having to change or recompile code, because the application logic (Java programs) and page design (FreeMarker templates) are separated. Templates do not become polluted with complex program fragments. This separation is useful even for projects where the programmer and the HTML page author is the same person, since it helps to keep the application clear and easily maintainable.

Although FreeMarker has some programming capabilities, it is nota full-blown programming language like PHP. Instead, Java programs prepare the data to be displayed (like issue SQL queries), and FreeMarker just generates textual pages that display the prepared data using templates.

  • Can be used to generate any kind of text: HTML, XML, RTF, Java source code, etc.
  • Easy to embed into your product: Lightweight. Does not require servlet environment (does not depend on javax.servlet classes).
  • Pluggable template loader: you can load templates from any sources; local files, database, etc.
  • You can do whatever you want with the generated text: store it in a local file, send it as e-mail, send it back to a Web browser from a Web application, etc.


FreeMarker is Free, with BSD-style license. It is OSI Certified Open Source Software. OSI Certified is a certification mark of the Open Source Initiative.


(JSR 223 implementation Groovy 1.5.4 ) -http://groovy.codehaus.org/

  • is an agile and dynamic language for the Java Virtual Machine
  • builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk
  • makes modern programming features available to Java developers with almost-zero learning curve
  • supports Domain-Specific Languages and other compact syntax so your code becomes easy to read and maintain
  • makes writing shell and build scripts easy with its powerful processing primitives, OO abilities and an Ant DSL
  • increases developer productivity by reducing scaffolding code when developing web, GUI, database or console applications
  • simplifies testing by supporting unit testing and mocking out-of-the-box
  • seamlessly integrates with all existing Java objects and libraries
  • compiles straight to Java bytecode so you can use it anywhere you can use Java
  • supports annotations, generics and enums,
  • offers meta-programming capabilities

Groovy is available under open source licenses.


(JSR 223 implementation Jaskell 1.0) -http://jaskell.codehaus.org/

Jaskell is a functional scripting programming language that runs in JVM. The name "Jaskell" stands for Java-Haskell, Haskell being the famous pure functional programming language.

Jaskell is designed not to be a better language, but a different one.

  • Most of the current scripting languages are Object-Oriented. Though they more or less have functional tastes, the heart of them are still Object-Oriented. One of the most important essences of functional programming (combinators) is yet to be brought into Java.
  • Jaskell brings with it higher order function, function currying, pattern match and monadic combinator support.
  • Monadic combinator is ideal for designing Domain Specific Language. It is relatively easy to tailor Jaskell runtime to make domain specific syntax look like simple atomic statements. See Neptune for a real example.
  • Jaskell bridges nicely between functional interpreter and Java. In fact, Jaskell is nothing but a Java library that passes Java objects in and out of the interpreter.

Jaskell is available under open source licenses.


(JSR 223 implementation Jelly 1.0) -http://commons.apache.org/jelly/

Jelly is a tool for turning XML into executable code. So Jelly is a Java and XML based scripting and processing engine. Jelly can be used as a more flexible and powerful front end to Ant such as in the Maven project, as a testing framework such as JellyUnit, in an intergration or workflow system such as werkflow or as a page templating system inside engines like Cocoon.

Jelly borrows many good ideas from both JSP custom tags, Velocity, Cocoon, Ant. Jelly can be used from the command line, inside Ant and Maven or inside a Servlet, Web Service, JMS MessageListener or embedded directly into your software.

Jelly has native support for a Velocity-like expression language called Jexl which is a superset of the JSP, JSTL and JSF expression languages as well as support for other pluggable expression languages like XPath via Jaxen, JavaScript, beanshell and Jython.

Jelly is completely extendable via custom tags in a similar way to JSP custom tags or Ant tasks. Though Jelly is really simple and has no dependencies either Servlets or JSP. So you could think of Jelly as similar to an XML-ized Velocity where the directives are XML tags. Or you could think of Jelly as a more flexible engine for processing Ant tasks with better expression, logic and looping support.

Jelly is also based on an XML pipeline architecture, like Cocoon, so that it is ideal for processing XML, scripting web services, generating dynamic web content or being part of a content generation system such as Cocoon.


Jelly is licensed under the Apache License, Version 2.0


(JSR 223 implementation JEP - Java Math Expression Parser 2.4.0) - http://www.singularsys.com/jep/

Jep is a Java library for parsing and evaluating mathematical expressions. With this package you can allow your users to enter an arbitrary formula as a string, and instantly evaluate it. Jep supports user defined variables, constants, and functions. A number of common mathematical functions and constants are included.


  • Small size (only 210KB as jar archive)
  • Fast evaluation
  • High precision using BigDecimals
  • Includes common math functions and operators
  • Supports Boolean expressions
  • Extendable and configurable architecture
  • Support for strings, vectors and complex numbers
  • Support for implicit multiplication
  • Allows declared or undeclared variables
  • Java 1.5 compatible
  • Supports Unicode characters
  • Extensive documentation
  • Includes JavaCC grammar from which the main classes are generated


To use Jep it is needed  to buy a license.


(JSR 223 implementation Jexl 1.0) -http://commons.apache.org/jexl/

Java Expression Language (JEXL) is an expression language engine which can be embedded in applications and frameworks. JEXL is inspired by Jakarta Velocity and the Expression Language defined in the JavaServer Pages Standard Tag Library version 1.1 (JSTL) and JavaServer Pages version 2.0 (JSP).

While JEXL is similar to the expression language defined in JSTL, it has improved upon the syntax in a few areas:

  • Support for invocation of any accessible method (see example above).
  • Added a general size() method, which works on:
    • String - returns length
    • Map - returns number of keys
    • List - returns number of elements.
  • Optional syntax for the 'empty' function : empty(obj)
  • Misc : '+' has been overloaded to be use as a String concatenation operator

JEXL is licensed under the Apache License, Version 2.0.


(JSR 223 implementation JudoScript 0.9) -http://www.judoscript.com/judo.html

Judo is a practical, functional scripting language. It is designed to cover the use cases of not only algorithmic/object-oriented/multi-threaded programming and Java scripting but also a number of major application domain tasks, such as scripting for JDBC, WSDL, ActiveX, OS, multiple file/data formats, etc. Despite its rich functionality, the base language is extremely simple, and domain support syntax is totally intuitive to domain experts, so that even though you have never programmed in Judo, you would have little trouble figuring out what the code does.

The key benefits of programming in Judo are productivity and maintainability, thanks to its rich, built-in functionality and the unprecedented emphasis on code conciseness and intuitiveness. Judo itself is a general-purpose language, and is strong for tasks like:

  • multi-source, multi-format data analysis, reporting or aggregation
  • automated tasks such as unit and system testing, batch processing jobs, system monitoring, etc.
  • software application prototyping at different levels and tiers
  • developing enterprise applications
  • quick ad hoc fixes


Judo is available under open source licenses. The source code  is available under LGPL license.


(JSR 223 implementation Pnuts 1.1) -https://pnuts.dev.java.net/

Pnuts is a script language for Java environment. It enables interaction with Java environment, simple Web scripting, customization for Java programs, and so on.

  • Simple and clean syntax
  • Interactive interpreter
  • Extensible through its module system
  • Customizable and embeddable through Pnuts API
  • Dynamic/static translation to JVM bytecode
  • One of the fastest scripting language implementations on JVM
  • Inherits many advantages of Java (security, portability, etc.)


  • The language is designed specially for Java Platform

Scripting language systems on JVM fall into two categories; one is porting of an existing language to Java platform, and the other is a new language from ground up.

Systems in the former category bring an additional value to the existing system. A common problem of systems in this category is that they have to keep it compatible with the existing system. Even if the models of the two languages differ, the difference has to be left as it was. For example, since most scripting languages have different type system from the host language, data type conversion between the languages is necessary. Not only that user has to understand and distinguish the two type systems in dual-language applications, but that it would significantly degrade the performance.

New languages specialized for Java, including Pnuts, do not have such restriction. All values in Pnuts are Java objects of well-defined Java classes/interfaces.

  • Modular API

Pnuts API provides a flexible interface to embed Pnuts into Pnuts applications. Many other systems fall short in this area.

  • A rich set of the standard modules

Pnuts provides off-the-shelf library functions as standard modules. Those functions make application development much simpler than Java-only solution. In addition, Pnuts has a sophisticated module system that allows users to add their own modules as needed for user's application.

  • High performance

Pnuts is one of the fastest scripting language implementations based on Java. Speed is important when a scripting engine is embedded into a large application, because scripting engines are likely to be a performance bottle-neck of the application.


Pnuts is available under SUN PUBLIC LICENSE Version 1.0.


(JSR 223 implementation Jython 2.2.1) -http://jython.sourceforge.net/Project/index.html

Jython is an implementation of the high-level, dynamic, object-oriented language Python seamlessly integrated with the Java platform. The predecessor to Jython, JPython, is certified as 100% Pure Java. Jython is freely available for both commercial and non-commercial use and is distributed with source code. Jython is complementary to Java and is especially suited for the following tasks:

  • Embedded scripting - Java programmers can add the Jython libraries to their system to allow end users to write simple or complicated scripts that add functionality to the application.
  • Interactive experimentation - Jython provides an interactive interpreter that can be used to interact with Java packages or with running Java applications. This allows programmers to experiment and debug any Java system using Jython.
  • Rapid application development - Python programs are typically 2-10X shorter than the equivalent Java program. This translates directly to increased programmer productivity. The seamless interaction between Python and Java allows developers to freely mix the two languages both during development and in shipping products.

There are numerous alternative languages implemented for the Java VM. The following features help to separate Jython from the rest:

  • Dynamic compilation to Java bytecodes - leads to highest possible performance without sacrificing interactivity.
  • Ability to extend existing Java classes in Jython - allows effective use of abstract classes.
  • Optional static compilation - allows creation of applets, servlets, beans, ...
  • Bean Properties - make use of Java packages much easier.
  • Python Language - combines remarkable power with very clear syntax. It also supports a full object-oriented programming model which makes it a natural fit for Java's OO design.




(JSR 223 implementation JRuby 1.1) -http://jruby.codehaus.org/

JRuby is an 100% pure-Java implementation of the Ruby programming language.


  • A 1.8.6 compatible Ruby interpreter written in 100% pure Java
  • Most builtin Ruby classes provided
  • Support for interacting with and defining java classes from within ruby
  • Bean Scripting Framework (BSF) support
  • Distributed under a tri-license (CPL/GPL/LGPL)


JRuby is available under open source licenses.


(JSR 223 implementation SISC 1.16.6 ) -http://sisc-scheme.org/

Scheme is a statically scoped and properly tail-recursive dialect of the Lisp programming language. It was designed to have an exceptionally clear and simple semantics and few different ways to form expressions. A wide variety of programming paradigms, including imperative, functional, and message passing styles, find convenient expression in Scheme.

SISC is an extensible Java based interpreter of the algorithmic language Scheme. SISC uses modern interpretation techniques, and handily outperforms all existing JVM interpreters (often by more than an order of magnitude).

In addition, SISC is a complete implementation of the language. The entire R5RS Scheme standard is supported, no exceptions. This includes a full number tower including complex number support, arbitrary precision integers and floating point numbers, as well as hygienic R5RS macros, proper tail recursion, and first-class continuations (not just the escaping continuations as in many limited Scheme systems). SISC also attempts to implement the standard as correctly as possible, while still providing exceptional performance.

SISC also provides useful real-world extensions, such as networking, elegant exception handling, a scope-friendly module system, support for SLIB, numerous SRFIs, and a Java foreign-function interface.

Finally, native functionality can be added through the use of Modules, extensions that may add new types, values, and functions to the language. These extensions can be packaged into scopable modules at the Scheme level as well.


SISC is released simultaneously under the terms of the Mozilla Public License (MPL) v1.1 and the GNU General Public License (GPL) v2. Users/Developers may choose which ever license suits their goals.


(JSR 223 implementation Sleep 2.0) -http://sleep.dashnine.org/


  • a multi-paradigm scripting language for the Java Platform
  • easy to learn with Perl and Objective-C inspired syntax
  • executes scripts fast with a small package size (~225KB)
  • excels at data manipulation, component integration, and distributed communication
  • is extensible and embeds into your Java applications
  • seamlessly utilizes Java objects and 3rd party libraries


Sleep source and binaries are released under the GNU Lesser General Public License.


(JSR 223 implementation Jacl(Tcl/Java) 1.3.3) - http://tcljava.sourceforge.net/docs/website/index.html

Tcl (Tool Command Language) is a very powerful but easy to learn dynamic programming language, suitable for a very wide range of uses, including web and desktop applications, networking, administration, testing and many more. Open source and business-friendly, Tcl is a mature yet evolving language that is truly cross platform, easily deployed and highly extensible.

Tcl/Java consists of two distinct packages, called Tcl Blend and Jacl.

Jacl is a self-contained implementation of a Tcl interpreter, written entirely in Java. Jacl also includes features that facilitate communication between a Java interpreter and a Tcl interpreter. Jacl is typically used to incorporate scripting functionality into an existing Java application. Jacl is the ideal solution for users that want to add Tcl scripting to a Java application, but don't want to deal with the complexities of native code that come with Tcl Blend.

Tcl Blend is a Tcl extension that makes use of JNI to facilitate communication between a Java interpreter and a Tcl interpreter. Tcl Blend is typically used to load a Java interpreter into an existing Tcl process, so that functionality implemented in Java can be accessed via Tcl. One can also load Tcl Blend and Tcl into a Java process, which is a great way to add scripting functionality to an existing Java application. Because Tcl Blend is a normal Tcl extension, one can use it with other popular Tcl extensions like Tk, Expect, and Itcl.

Tcl Blend and Jacl define both a Tcl API and a Java API that make it easy to call Java code from Tcl or call Tcl code from Java. For example, one could allocate a Java object in a Tcl script and interactively invoke Java methods on the object. It is also easy to use the supplied API to evaluate a Tcl procedure from a Java method or implement Tcl procudures in Java. The flexible API and wealth of implementation options provided by the Tcl/Java project make integrating Tcl and Java easy.


Jacl is available under open source licenses.


(JSR 223 implementation Velocity 1.5) -http://velocity.apache.org/

Velocity is a Java-based template engine. It permits anyone to use a simple yet powerful template language to reference objects defined in Java code.

When Velocity is used for web development, Web designers can work in parallel with Java programmers to develop web sites according to the Model-View-Controller (MVC) model, meaning that web page designers can focus solely on creating a site that looks good, and programmers can focus solely on writing top-notch code. Velocity separates Java code from the web pages, making the web site more maintainable over its lifespan and providing a viable alternative to Java Server Pages (JSPs) or PHP.

Velocity's capabilities reach well beyond the realm of the web; for example, it can be used to generate SQL, PostScript and XML (see Anakia for more information on XML transformations) from templates. It can be used either as a standalone utility for generating source code and reports, or as an integrated component of other systems. For instance, Velocity provides template services for the Turbine web application framework, together resulting in a view engine facilitating development of web applications according to a true MVC model.

Velocity is licensed under the Apache License, Version 2.0.


(JSR 223 implementation Resin 3.1/Quercus) -http://www.caucho.com/resin-3.0/quercus/

Quercus is Caucho Technology's fast, open-source, 100% Java implementation of the PHP language.

The real benefits come from developing mixed Java/PHP applications:

  • PHP libraries written in Java are fast, safe, and relatively easy to develop, compared with C libraries. Since Java is the library language, developers won't need to be paranoid about third-party libraries having C-memory problems or segvs.
  • PHP applications can take advantage of Java libraries and capabilities like JMS, SOA frameworks, Hibernate, or Spring. (Or EJB if you really wanted.)
  • Java application can move presentation code to PHP, leaving behind templating systems, or languages with small libraries, and taking advantage of PHP flexibility and capability.


Resin 3.1 Open Source is available under the GNU Public License (GPL).


是我写错了,最近在研究Java Content Repository, 所以瞬间混乱了.