简体   繁体   English

我如何实际运行Rhino?

[英]How do I actually run Rhino?

I've read through the docs here: Mozilla's 'Scripting Java' 我在这里阅读了文档: Mozilla的'脚本Java'

These examples don't answer my question either: Rhino Liveconnect example 这些例子也没有回答我的问题: Rhino Liveconnect示例

How do my javascript files know where to find "java.lang" for example? 我的javascript文件如何知道在哪里找到“java.lang”? Of course it works inside the Rhino shell, but I need to run java code from inside my javascript files, not from the shell. 当然它可以在Rhino shell中运行,但是我需要从我的javascript文件中运行java代码,而不是从shell运行。 I can only see .java files in the downloaded source. 我只能在下载的源代码中看到.java文件。

I want to call serverside java methods in my serverside nodejs javascript. 我想在我的服务器端nodejs javascript中调用serverside java方法。 Doesn't Rhino somehow need to be started up to provide my javascript with the ability to comprehend java? 是不是需要启动Rhino来为我的javascript提供理解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? 编辑: @eee所以,如果我理解正确,Rhino实际上并没有让我从javascript运行java,它只是将我的所有javascript翻译成java .class文件......毕竟我必须在java文件中执行? That kind of defeates the purpose of calling java from javascript. 这种打败了从javascript调用java的目的。 The whole idea is to be able to call any java code from inside my javascript code without having to build new java libraries. 整个想法是能够从我的javascript代码中调用任何java代码,而无需构建新的java库。

Doesn't that mean that I can't use Rhino? 这是不是意味着我不能使用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. Nodejs使用V8引擎来执行javascript,所以我假设V8和Rhino都不能使用单个javascript文件...我希望我可以调用java方法,这会启动Rhino,它会转换那些调用到Java。 Java itself would then return the variables filles with some data. 然后,Java本身将返回带有一些数据的变量filles。

@Peter: Why http calls? @Peter:为什么要打电话? Both my javascript and my java lie on the same server for now. 我的javascript和我的java现在都在同一台服务器上。 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? 我创建了一堆.class文件,然后调用'java myfile.class -v“firstvar”-x“secondvar”'..我理解正确吗?

Rhino does actually let me run java from javascript scripts. Rhino 确实让我从javascript脚本运行java。 There is not much to do. 没什么可做的。 LiveConnect gives you access to everything in the java.* package. LiveConnect使您可以访问java。*包中的所有内容。 If you want your own code to be accessible, you just need to add your class (compiled Java code) to the application's classpath. 如果您希望自己的代码可以访问,则只需将类(已编译的Java代码)添加到应用程序的类路径中。

I want to call serverside java methods in my serverside nodejs javascript. 我想在我的服务器端nodejs javascript中调用serverside java方法。

Rhino is a javascript interpreter, meaning it runs javascript code. Rhino是一个javascript解释器,意味着它运行 javascript代码。 V8 is NodeJS' javascript interpreter. V8是NodeJS的javascript解释器。 You must chose either Rhino or V8. 您必须选择Rhino或V8。 V8 is in C++ and is deeply embedded in NodeJS. V8采用C ++,深深嵌入NodeJS中。 Rhino is in Java and can't replace V8 easily. Rhino是Java,不能轻易取代V8。 There are projects (long term) to port NodeJS on Rhino, but don't wait for that unless you are ready to get involved. 有一些项目(长期)在Rhino上移植NodeJS,但除非你准备好参与,否则不要等待。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM