public static void main(String[] args){ System.setProperty(ClientLogger.CLIENT_LOG_LEVEL,"OFF"); //SpringApplication.run(SrmSettleAccountApplication.class, args); try { System.out.println(Thread.currentThread().getName() + "===>main-"); ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine engine = scriptEngineManager.getEngineByExtension("js"); engine.eval(scriptCode()); }catch (Exception e) { e.printStackTrace(); } } static String scriptCode() throws Exception { String file = "/Users/yangyb/node/global_modules/bin/app.js"; String script = StreamUtils.copyToString(new FileInputStream(new File(file)), Charset.defaultCharset()); System.out.println(script); return script; }
public class BizImp implements Biz {
public BizImp() {
}
public void a(){
System.out.println(Thread.currentThread().getName() + "===>a-");
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
public static void b(){
System.out.println(Thread.currentThread().getName() + "===>b-");
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
a.js module.exports = 'Hello World!'; b.js var msg = require('./a.js'); var BizImp = Java.type('org.srm.settleaccount.BizImp'); print("logInfo:", msg); var BigDecimal = Java.type('java.math.BigDecimal'); function process(){ var amount = 1; var percentage=1; var result = new BigDecimal(amount).multiply(new BigDecimal(percentage)).divide(new BigDecimal("100"), 2, BigDecimal.ROUND_HALF_EVEN); print(result); new BizImp().a(); BizImp.b(); print("say:"); } process();
./browserify demo/b.js -o app.js
标签:脚本,es6,System,JAVA,BigDecimal,BizImp,js,var,new From: https://www.cnblogs.com/gstsyyb/p/17183571.html