JVM虚拟机(1)_调用Jvm虚拟机执行Js代码

JVM虚拟机(1)_调用Jvm虚拟机执行Js代码

package com.lius.test;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.function.Function;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

import com.lius.funs.funResources;
/**
 * 调用Jvm虚拟机执行Js代码
 * @author Administrator
 *
 */
public class testJs {
public static void main(String[] args) throws ScriptException {
	//创建jvm实例
	ScriptEngineManager manage = new ScriptEngineManager();
	//获取JavaScript的jvm
	ScriptEngine jsManage = manage.getEngineByName("JavaScript");
	//打印jvm类名
	System.out.println(jsManage.getClass().getName());
	//获取文件内容
	String con = funResources.readStreamFun.apply("src/com/lius/resources/test.js");
	System.out.println(jsManage.eval(con));//调用jvm执行js代码
}

}

 

你可能感兴趣的:(JVM虚拟机)