Java ScriptEngine supported languages

..I know for a fact that JavaScript is supported,..

ECMAscript, technically.

.. but I couldn't find any other languages to work with it. Is, for example, Ruby implemented?

No. The ECMAscript engine is the only one included by default, the last time I heard.

Update

The comments of Pointy below, suggest that the Nashorn engine has been deprecated and will be removed 'soon'.


Not in ScriptEngine, but you can still use BSF. From the Apache Commons Bean Scripting Framework, you can find it's Documentation here. -

BSF 2.x supports several scripting languages currently:

  • Javascript (using Rhino ECMAScript, from the Mozilla project)
  • NetRexx (an extension of the IBM REXX scripting language in Java)
  • Commons JEXL
  • Python (using Jython)
  • Tcl (using Jacl)
  • XSLT Stylesheets (as a component of Apache XML project's Xalan and Xerces)

In addition, the following languages are supported with their own BSF engines:

  • Java (using BeanShell, from the BeanShell project)
  • Groovy
  • Groovy Monkey
  • JLog (PROLOG implemented in Java)
  • JRuby
  • JudoScript
  • ObjectScript
  • ooRexx (Open Object Rexx), using BSF4ooRexx.

Here is a script to determine all languages on your system:

import java.util.List;
import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngineFactory;


public class Test {

public static void main(String[] args)
{
    ScriptEngineManager mgr = new ScriptEngineManager();
    List<ScriptEngineFactory> factories = mgr.getEngineFactories();
    for (ScriptEngineFactory factory : factories)
    {
        System.out.println("ScriptEngineFactory Info");
        String engName = factory.getEngineName();
        String engVersion = factory.getEngineVersion();
        String langName = factory.getLanguageName();
        String langVersion = factory.getLanguageVersion();
        System.out.printf("\tScript Engine: %s (%s)\n", engName, engVersion);
        List<String> engNames = factory.getNames();
        for (String name : engNames)
        {
            System.out.printf("\tEngine Alias: %s\n", name);
        }
        System.out.printf("\tLanguage: %s (%s)\n", langName, langVersion);
        }
    }

}

Hope this helps.


The Java ScriptEngine API will work with all JSR-223 Scripting Languages. I haven't found a well documented complete list of these before but this post does a pretty good job, Where can I find a list of available JSR-223 scripting languages? Here is one list from that post,

JSR-223 script engines

  • AWK
  • BeanShell
  • ejs
  • FreeMarker
  • Groovy
  • Jaskell
  • Java
  • JavaScript
  • JavaScript (Web Browser)
  • Jelly
  • JEP
  • Jexl
  • jst
  • JudoScript
  • JUEL
  • OGNL
  • Pnuts
  • Python
  • Ruby
  • Scheme
  • Sleep
  • Tcl
  • Velocity
  • XPath
  • XSLT

JSR 223 script engines maintained elsewhere

  • JavaFX Script
  • ABCL
  • AppleScript
  • Bex script
  • OCaml Scripting Project
  • PHP
  • PHP (another one)
  • Python
  • Smalltalk
  • CajuScript
  • MathEclipse

Most have a special implementation for it to work. For example python alone will not work you need the Jython jar added to the class path. Same for Ruby you'll need JRuby.