使用 Rhino 在 Java 中编译 JavaScript
我正在我的 Java 应用程序中测试 Rhino JavaScript 脚本引擎。
启动时,我加载所有 .js 文件并在 Java 中编译它们,如下所示:
这一切都很好,但是离线 .js->java .class 编译器:http://www.mozilla.org/rhino/jsc.html 有各种奇特的东西优化:http://www.mozilla.org/rhino/opt.html
如何我是否可以在 Java 内部进行这些优化编译?
他们的 API 文档也有吗?他们主页上的 API 文档链接已损坏; http://www.mozilla.org/rhino/doc.html
编辑:我无法使用离线编译器,因为我希望用户可以轻松拖放脚本并重新启动。
I'm testing out Rhino JavaScript script engine inside my Java application.
At startup, I load all .js files and compile them inside of Java like this:
- Are there any tips & tricks for making rhino perform faster?
- http://www.javalobby.org/java/forums/t87870.html
That is all well and great, but the offline .js->java .class compiler: http://www.mozilla.org/rhino/jsc.html has all sorts of fancy optimizations: http://www.mozilla.org/rhino/opt.html
How do I compile inside of Java with those optimizations?
Also were is their API docs for this? Their API doc link on their main page is broke; http://www.mozilla.org/rhino/doc.html
Edit: I can't use the offline compiler because I want it to be easy for users to drag/drop their scripts in and restart.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
toolsrc\org\mozilla\javascript\tools\jsc\
中的Main.java
应该会给你一些如何做到这一点的想法。基本上,您可以使用 CompilerEnvirons 类设置优化级别。之后,您应该使用
CompilerEnvirons
作为第一个参数来创建ClassCompiler
对象的新实例。从源头看:
Main.java
insidetoolsrc\org\mozilla\javascript\tools\jsc\
should give you some idea how to do it.Basically, you set optimization level using
CompilerEnvirons
class. After that, you should create a new instance of theClassCompiler
object usingCompilerEnvirons
as the first parameter.From the source: