我如何实际运行Rhino?
我已阅读此处的文档: Mozilla 的“Scripting Java”
这些示例不回答我的问题: Rhino Liveconnect 示例
我的例如,javascript 文件知道在哪里可以找到“java.lang”吗?当然,它可以在 Rhino shell 内运行,但我需要从 javascript 文件内部运行 java 代码,而不是从 shell 运行。我只能在下载的源代码中看到 .java 文件。
我想在我的服务器端nodejs javascript 中调用服务器端java 方法。难道Rhino不需要以某种方式启动来为我的javascript提供理解java的能力吗?
编辑: @eee所以,如果我理解正确的话,Rhino实际上并不让我从javascript运行java,它只是将我所有的javascript转换成java .class文件......毕竟我必须在java文件中执行?这违背了从 javascript 调用 java 的目的。整个想法是能够从我的 javascript 代码中调用任何 java 代码,而无需构建新的 java 库。
这不是说我不能使用Rhino吗? Nodejs 使用 V8 引擎来执行 javascript,所以我假设 V8 和 Rhino 不能同时使用单个 javascript 文件...我希望我可以调用 java 方法,这将启动 Rhino 来翻译这些调用到爪哇。 然后,Java 本身将返回填充了一些数据的变量。
@Peter:为什么要调用http?我的 javascript 和 java 目前都位于同一服务器上。不管怎样,你所说的并不完全需要Rhino,不是吗?我会创建一堆 .class 文件,然后调用 'java myfile.class -v "firstvar" -x "secondvar"'.. 我理解正确吗?
I've read through the docs here: Mozilla's 'Scripting Java'
These examples don't answer my question either: Rhino Liveconnect example
How do my javascript files know where to find "java.lang" for example? Of course it works inside the Rhino shell, but I need to run java code from inside my javascript files, not from the shell. I can only see .java files in the downloaded source.
I want to call serverside java methods in my serverside nodejs javascript. Doesn't Rhino somehow need to be started up to provide my javascript with the ability to comprehend java?
Edit:
@eee So if I understand correctly, Rhino doesn't actually let me run java from javascript, it just translate all my javascript into java .class files...which I have to execute inside a java file after all? That kind of defeates the purpose of calling java from javascript. The whole idea is to be able to call any java code from inside my javascript code without having to build new java libraries.
Doesn't that mean that I can't use Rhino? Nodejs uses the V8 engine to execute javascript, so I assume that a single javascript file can't be used by both V8 and Rhino...I was hoping that I could call java methods, which would start up Rhino which would translate those calls to Java.
Java itself would then return the variables filles with some data.
@Peter: Why http calls? Both my javascript and my java lie on the same server for now. Anyway, what you are saying wouldn't exactly require Rhino, would it? I'd create a bunch of .class files and then call 'java myfile.class -v "firstvar" -x "secondvar"'.. am I understanding you correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Rhino 实际上让我从 javascript 脚本运行 java。没什么可做的。 LiveConnect 使您可以访问 java.* 包中的所有内容。如果您希望自己的代码可供访问,只需将您的类(编译后的 Java 代码)添加到应用程序的类路径中即可。
Rhino 是一个 javascript 解释器,这意味着它运行 javascript 代码。 V8 是 NodeJS 的 JavaScript 解释器。您必须选择 Rhino 或 V8。 V8 采用 C++ 语言,并深深嵌入 NodeJS 中。 Rhino 是 Java 语言,无法轻易取代 V8。有一些项目(长期)可以将 NodeJS 移植到 Rhino 上,但除非您准备好参与,否则不要等待。
Rhino does actually let me run java from javascript scripts. There is not much to do. LiveConnect gives you access to everything in the java.* package. If you want your own code to be accessible, you just need to add your class (compiled Java code) to the application's classpath.
Rhino is a javascript interpreter, meaning it runs javascript code. V8 is NodeJS' javascript interpreter. You must chose either Rhino or V8. V8 is in C++ and is deeply embedded in NodeJS. Rhino is in Java and can't replace V8 easily. There are projects (long term) to port NodeJS on Rhino, but don't wait for that unless you are ready to get involved.