Java by API/javax.script/ScriptEngineManager
new ScriptEngineManager()
import java.util.List;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
public class Main {
public static void main(String[] args) {
// create ScriptEngineManager
ScriptEngineManager manager = new ScriptEngineManager();
List<ScriptEngineFactory> factoryList = manager.getEngineFactories();
for (ScriptEngineFactory factory : factoryList) {
System.out.println(factory.getEngineName());
System.out.println(factory.getLanguageName());
}
}
}
ScriptEngineManager: getEngineByMimeType(String mimeType)
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
public class Main{
public static void main(String[] args) {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine jsEngine = manager.getEngineByMimeType("text/javascript");
if (!(jsEngine == null)) {
System.out.println("text/javascript MIME type retrieved:" + jsEngine);
}
ScriptEngine jsEngine2 = manager.getEngineByMimeType("text/vbscript");
if (jsEngine2 == null)
System.out.println("\nNo supported script engine found for text/vbscript MIME type.");
}
}
ScriptEngineManager: getEngineByName(String shortName)
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class Main {
public static void main(String[] args) {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
String script = "print ("www.jexp.ru")";
try {
engine.eval(script);
} catch (ScriptException e) {
e.printStackTrace();
}
}
}