Java ScriptEngine supported languages

user1241335 picture user1241335 · Nov 16, 2013 · Viewed 19.8k times · Source

Java has a ScriptEngine system that allows you to run/evaluate statements in a different language.
I know for a fact that JavaScript is supported, but I couldn't find any other languages to work with it.
Is, for example, Ruby implemented?

Answer

hjk321 picture hjk321 · Jun 26, 2016

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.