This example shows how to get the details of the script engines supported by your JVM. Java supports the different script engines that can be retrieved and used depends upon the client side scripts. Java provides javax.script.ScriptEngineFactory for storing all the script engine details like script engine name, version, default script engine, language, etc. You can use getEngineFactories() method in the javax.script.ScriptEngineManager to get the list of factories and the associated script engines. Lets look at the example. ScriptEngineFactoryExample.java
[code lang=”java”] package javabeat.net.script;import java.util.List;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
/**
* Java ScriptEngineFactory Details Example
*
* @author Krishna
*
*/
public class ScriptEngineFactoryExample {
public static void main(String[] args){
// Create ScriptEngineManager
ScriptEngineManager engineManager = new ScriptEngineManager();
//Get the ScriptEngineFactory List
List list = engineManager.getEngineFactories();
//Print the supported ScriptEngine Names
System.out.println(list.get(0).getNames());
//Print the supported ScriptEngine MimeTypes
System.out.println(list.get(0).getMimeTypes());
//Print the default script engine
System.out.println(list.get(0).getEngineName());
}
}
[/code]
Output…
[code] [js, rhino, JavaScript, javascript, ECMAScript, ecmascript] [application/javascript, application/ecmascript, text/javascript, text/ecmascript] Mozilla Rhino[/code]