【发布时间】:2011-06-30 15:54:28
【问题描述】:
我将以下 JavaScript 文件“test.js”编译到“test.class”中:
var test = (function () {
var that = {};
that.addNumbers = function (a, b) {
return a+b;
};
return that;
}());
我想在简单的Java程序“run.java”中调用编译后的JavaScript函数“test.addNumbers(1,2)”:
public class run {
public static void main(String[] args) throws Exception {
Context cx = Context.enter();
try {
Scriptable scope = cx.initStandardObjects();
// HOW TO CALL THE METHOD, Test.addNumbers(1,2)? Please help me!
} finally {
Context.exit();
}
}
}
我尝试了很多方法,但都失败了。我阅读了 Rhino 教程并查看了许多文章和示例,但它们只显示了如何从命令行或源文件“test.js”调用 JavaScript 方法。 我需要从已编译的“test.class”文件中调用该方法。
非常感谢您的帮助!
【问题讨论】:
标签: java javascript compiler-construction embed rhino