Upgrading the javax.scripting version of Rhino.

512 views
Skip to first unread message

Michael Haefele

unread,
Jan 26, 2011, 3:33:16 PM1/26/11
to mozilla-rhino
Hello,

I'm interested in upgrading the version of Rhino used in
javax.scripting.
(At least initially because envjs says not to use the bundled one
http://www.envjs.com/doc/guides#running-rhino).

I was expecting something similar to
ScriptEngineManager factory = new ScriptEngineManager();
factory.registerEngineName("JavaScript", );
ScriptEngine engine = factory.getEngineByName("JavaScript");
...

...but I can't seem to locate anything resembling an implementation of
ScriptEngineFactory for this.
Am I missing something?

Thanks,
Mike

Kevin Krouse

unread,
Jan 26, 2011, 4:47:34 PM1/26/11
to mozilla-rhino, Michael Haefele

Hi Mike,

You can use the JSR 223 js-engine.jar found at:

https://scripting.dev.java.net/servlets/ProjectDocumentList

Download the jsr223-engines.tar.gz, extract the js-engine.jar. There is a
META-INF/services/javax.script.ScriptEngineFactory file that registers the
script engine. I think you can request this new script engine with
something
like 'factory.getEngineByName("rhino-nonjdk")'.

--
Kevin

Michael Haefele

unread,
Jan 27, 2011, 12:58:12 PM1/27/11
to mozilla-rhino
Good deal. So far it looks like it's working.
Thanks for the help!

In case anyone is going down a similar path, I ended up doing the
following to get a mavenized version of this.

1. Exported the scripting/engines/javascript source using cvs.
* See https://scripting.dev.java.net/source/browse/scripting/
2. Added a basic pom.xml file
3. moved the src/ directory contents to src/main/java/
4. moved the META-INF directory to src/main/resources/
5. deleted bin, lib and make directory
6. Added a dependency on the latest rhino version to the pom.xml
<dependencies>
<dependency>
<groupId>rhino</groupId>
<artifactId>js</artifactId>
<version>1.7R2</version>
</dependency>
</dependencies>
7. Added some sanity check tests to src/test/java

That worked like a charm and (being mavenized) will be easy to upgrade
to newer versions of rhino.

Also, for bonus points, I modified RhinoScriptEngineFactory to return
a more accurate version of the Rhino Engine (it was hardcoded to
1.6R7).

Added the following method to RhinoScriptEngineFactory:
private String getRhinoVersion()
{
// The rhino version message looks like "Rhino 1.7 release 2
2009 03 22"
// We need something of the form "1.7R2"
String longVersion =
ScriptRuntime.getMessage("implementation.version", null);
Pattern pattern = Pattern.compile("Rhino ([0-9.]*)( release
([0-9.]*))?");
Matcher matcher = pattern.matcher(longVersion);

if (matcher.find() && matcher.group(1) != null)
{
String version = matcher.group(1);
if (matcher.group(3) != null)
version += "R" + matcher.group(3);

return version;
}

return "unknown";
}

And replaced
} else if (key.equals(ScriptEngine.ENGINE_VERSION)) {
return "1.6R7";
with
} else if (key.equals(ScriptEngine.ENGINE_VERSION)) {
return getRhinoVersion();

Mike

tombr...@gmail.com

unread,
Aug 21, 2015, 7:53:04 PM8/21/15
to mozilla-rhino, michael...@parityenergy.com
Hello,

I know this is an old thread, but I'm running into the same problem (I want to use JSR-223 but I don't want the Java7 stock version of Rhino; and I want to use Rhino instead of Nashorn in Java8)

I have searched for RhinoScriptEngineFactory, but I am unable to find any easy-to-include versions (e.g. maven friendly).

What to the members of this group recommend to someone who wants a standard script interface that can cover multiple languages (Apache BSF or JSR-223) who doesn't want to risk incompatibility between Java7/Rhino and 8/Nashorn?

Thanks in advance!

--Tom
Reply all
Reply to author
Forward
0 new messages