JVM missing Rhino
Asked Answered
D

1

4

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.

Dzungaria answered 10/1, 2011 at 17:21 Comment(4)
That's pretty weird. What JVM version does the server support? In any case, just adding the stock Rhino jar won't help - the Sun version is initialized in a different way. I don't know where you'd get a JDK6 VM that manages to not have Rhino in it.Macklin
Andrei, this needs more details. What's running on the server (Tomcat, JBoss, Apache on its own)? The usual reason for this would be something to do with your classpath and how you've added the jar to the project.Eichler
Server : FreeBSD 8.1-STABLE FreeBSD 8.1-STABLE Java : Diablo Java(TM) SE Runtime Environment (build 1.6.0_07-b02) Diablo Java HotSpot(TM) 64-Bit Server VM (build 10.0-b23, mixed mode) I'm using Eclipse to develop the project, so i added the jar this way : Project > Properties > Java Build Path > Libraries > Add jarDzungaria
@Pointy: Only Sun's JDK has Rhino in it, and only Sun's JDK has Rhino in it. If you don't use Sun's JDK but for example IBM's, or if you don't use a JDK but a JRE (quite likely on a server), then you don't have Rhino. Besides, it's not really "Rhino" anyway, it's a stripped-down version. In particular, it's only the interpreter without the compiler, which will pretty much guarantee you godawful performance.Actualize
D
10

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.

Disbar answered 10/1, 2011 at 17:58 Comment(1)
an exact description of what is missing or different in the JDK6 version of rhino can be found here: docs.oracle.com/javase/6/docs/technotes/guides/scripting/…Canon

© 2022 - 2024 — McMap. All rights reserved.