java程序员-http://www.it-ebooks.info/

年轻的我,脚踩大地,仰望天空,路还很长....

博客园 首页 新随笔 联系 订阅 管理
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

posted on 2023-03-06 13:47  gstsyyb  阅读(760)  评论(0编辑  收藏  举报