How do I get the supported scripting engine?

package org.kodejava.script;

import javax.script.ScriptEngineManager;
import javax.script.ScriptEngineFactory;
import java.util.List;

public class GetSupportedScriptingEngine {
    public static void main(String[] args) {
        // Creating an instance of ScriptEngineManager an get the list
        // of available ScriptEngineFactory.
        ScriptEngineManager manager = new ScriptEngineManager();
        List<ScriptEngineFactory> factories = manager.getEngineFactories();

        for (ScriptEngineFactory factory : factories) {
            System.out.println(
                    "EngineName      = " + factory.getEngineName());
            System.out.println(
                    "EngineVersion   = " + factory.getEngineVersion());
            System.out.println(
                    "LanguageName    = " + factory.getLanguageName());
            System.out.println(
                    "LanguageVersion = " + factory.getLanguageVersion());
            System.out.println(
                    "Extensions      = " + factory.getExtensions());
            System.out.println();

            List<String> names = factory.getNames();
            for (String name : names) {
                System.out.println("Engine Alias = " + name);
            }
        }
    }
}

The code above produces the following information.

EngineName      = Graal.js
EngineVersion   = Development Build
LanguageName    = ECMAScript
LanguageVersion = ECMAScript 262 Edition 11
Extensions      = [js, mjs]

Engine Alias = js
Engine Alias = JS
Engine Alias = JavaScript
Engine Alias = javascript
Engine Alias = ECMAScript
Engine Alias = ecmascript
Engine Alias = Graal.js
Engine Alias = graal.js
Engine Alias = Graal-js
Engine Alias = graal-js
Engine Alias = Graal.JS
Engine Alias = Graal-JS
Engine Alias = GraalJS
Engine Alias = GraalJSPolyglot

Maven Dependencies

<dependencies>
    <dependency>
        <!--https://search.maven.org/remotecontent?filepath=org/graalvm/js/js/21.3.0/js-21.3.0.jar-->
        <groupId>org.graalvm.js</groupId>
        <artifactId>js</artifactId>
        <version>21.3.0</version>
    </dependency>
    <dependency>
        <!--https://search.maven.org/remotecontent?filepath=org/graalvm/js/js-scriptengine/21.3.0/js-scriptengine-21.3.0.jar-->
        <groupId>org.graalvm.js</groupId>
        <artifactId>js-scriptengine</artifactId>
        <version>21.3.0</version>
    </dependency>
</dependencies>

Maven Central Maven Central

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.