JVM 缺少 Rhino

发布于 2024-10-11 06:28:42 字数 258 浏览 8 评论 0原文

我有一个使用 ScriptEngine 处理一些 javascript 的项目,并且在我的机器上运行良好,但是当我将项目的 jar 发送到服务器时,我发现服务器的 JVM 没有内置 Rhino,当代码调用 a

new ScriptEngineManager().getEngineByName("javascript");

我去了rhino的下载页面,获取最新版本,并从中提取了js.jar,将jar添加到项目中,但仍然有同样的问题。

I have a project that uses the ScriptEngine to process some javascript, and worked well on my machine, but when i send the projects's jar to the server, i had discovered that the server's JVM doesn't have Rhino built-in, returning null when the code calls a

new ScriptEngineManager().getEngineByName("javascript");

I went to the rhino's download page, get the most recent version, and extracted the js.jar from it, added the jar on the project, but still have the same problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪 2024-10-18 06:28:42

JavaScript 引擎仅包含在 Sun/Oracle JDK 中。如果您使用其他一些 Java 实现,例如 IBM J9 或 Oracle JRockit(很可能在服务器上),或者如果您不使用 Sun/Oracle JDK,而是使用 Sun/Oracle JRE(更可能在服务器上),那么您没有获得 JavaScript 引擎。

您需要使用Sun 的完整JDK。

另请注意,JDK6 附带的 JavaScript 引擎不是 Rhino,它是几年前已过时版本的 Rhino 的精简版。特别是,它缺少编译器,这意味着性能可能会很差。

另请注意,Rhino 和 JDK6 JavaScript 引擎之间的 API 不一定兼容,即使您设法找到它所基于的过时版本的 Rhino。因此,如果您想在部署中使用Rhino,那么您最好在开发中也使用它。

最后但并非最不重要的一点是:仅仅因为您在 Eclipse 项目文件中输入了一些条目,并不意味着您的服务器的类路径会发生神奇的变化。您需要确保所有类路径都已正确设置。我对 FreeBSD 没有任何经验,但我很确定包管理系统(在本例中为 FreeBSD ports)在 port install rhino 后至少会部分处理这个问题。

The JavaScript Engine is only included in the Sun/Oracle JDK. If you use some other Java implementation like IBM J9 or Oracle JRockit (quite likely on a server), or if you don't use the Sun/Oracle JDK but the Sun/Oracle JRE (even more likely on a server), then you don't get the JavaScript engine.

You need to use Sun's full JDK.

Note also that the JavaScript engine shipped with JDK6 is not Rhino, it's a stripped-down lobotomized version of a several year old obsolote release of Rhino. In particular, it is missing the compiler, which means that performance will probably suck.

Also note that the API is not necessarily compatible between Rhino and the JDK6 JavaScript engine, even if you manage to find that obsolete release of Rhino that it is based on. So, if you want to use Rhino in deployment, you'd better use it in development, too.

And last but not least: just because you make some entry in your Eclipse project file, doesn't mean that your server's classpath is going to magically change. You need to make sure that all your classpaths are properly set up. I don't have any eperience with FreeBSD, but I'm pretty sure that the package management system (FreeBSD ports in this case) is going to at least partially take care of that after a port install rhino.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文