Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.FileReader;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class Main {
    public static Object invokeFunction(String filepath, String funcname, Object... params) {
        try {
            ScriptEngineManager sem = new ScriptEngineManager();
            ScriptEngine jsEngine = sem.getEngineByName("js");
            jsEngine.eval(new FileReader(filepath));
            Invocable invocable = (Invocable) jsEngine;
            return invocable.invokeFunction(funcname, params);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}