ITKeyword,专注技术干货聚合推荐

注册 | 登录

Java执行js脚本

标签:

相关推荐:使用 java 来调用sql plus执行oracle ddl dml脚本

使用bat 脚本,完成用sql plus 执行sql 脚本的功能@echo offcd %3sqlplus %1/%2@%6 as sysdba @%4echo 1exit可以用java来调用public boolean exec

http://my.oschina.net/sniperLi/blog/530338package cn.sniper.spider.utils; import java.io.BufferedReader;import java.io.FileInputStream;import java.io.InputStream;import java.io.InputStreamReader;import java.io.StringReader;import java.net.URL; import javax.script.Invocable;import javax.script.ScriptEngine;import javax.script.ScriptEngineManager; import org.junit.Test; public class Java4JsUtil {

@Test

public void testJs1() throws Exception {

ScriptEngineManager scriptEngineManager = new ScriptEngineManager();

ScriptEngine engine = scriptEngineManager.getEngineByExtension("js");

StringReader reader = new StringReader("function getNum(num){return num}");

engine.eval(reader);

Invocable invocable = (Invocable)engine;

Object result = invocable.invokeFunction("getNum", "2");

System.out.println(result);

}

@Test

public void testJs2() throws Exception {

ScriptEngineManager scriptEngineManager = new ScriptEngineManager();

ScriptEngine engine = scriptEngineManager

相关推荐:[io.js]CMD执行js脚本来实现文本文件拷贝

windows为例,下载安装文件直接安装完成,无需其他配置。官网:https://iojs.org写一个拷贝文件的脚本,功能是:将src文件中的内容拷贝覆盖到dst文件中。

.getEngineByExtension("js");

BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\test.js")));

engine.eval(reader);

Invocable invocable = (Invocable)engine;

Object result = invocable.invokeFunction("getNum", "2");

System.out.println(result);

}

@Test

public void testOnlineJs() throws Exception {

ScriptEngineManager scriptEngineManager = new ScriptEngineManager();

ScriptEngine engine = scriptEngineManager.getEngineByExtension("js");

URL url2 = new URL("http://10.161.56.231:8888/tjfxpt/resources/js/common/common.js");

InputStream inputStream = url2.openStream();

BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

System.out.println(reader.readLine());

engine.eval(reader);

Invocable invocable = (Invocable)engine;

Object result = invocable.invokeFunction("fmoney", new Integer[]{10, 2});

System.out.println(result);

}

}

http://my.oschina.net/sniperLi/blog/530338package cn.sniper.spider.utils; import java.io.BufferedReader;import java.io.FileInputStream;import java.io.InputStream;import...

相关阅读排行


用户评论

游客

相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。