• Home
    • View
    • Login
    This page
    • Normal
    • Export PDF
    • Export Word
    • Attachments
    • Page Information

    Loading...
  1. Dashboard
  2. Nashorn
  3. Main
  4. Using Rhino JSR-223 engine with JDK8

Using Rhino JSR-223 engine with JDK8

  • Created by Sundararajan Athijegannathan, last modified on Apr 07, 2014

Using Rhino JSR-223 engine with JDK8

Why?

Mozilla Rhino based JSR-223 (javax.script) engine has been removed in Oracle's JDK8 implementation. In JDK8, Nashorn engine replaces Rhino based jsr-223 engine. It is recommended that you migrate your script application to Nashorn. But, to have time to migrate your JavaScript code to nashorn, you may want to stick to Rhino based jsr-223 implementation on jdk8 (as interim solution). If this is so, this document is for you.

Step 1 get Rhino

Clone Rhino source code from this git repo, into "$rhino_dir"

https://github.com/mozilla/rhino

Use ant to build js.jar

    $rhino_dir/build/rhino1_7R5pre/js.jar

If you want to get pre-built binary instead, you can download from here:

    https://github.com/downloads/mozilla/rhino/rhino1_7R4.zip

In either way, you'd get js.jar file in this step.

Step 2 get JSR-223 script engine on Rhino

JSR-223 engine over Rhino is available from java.net scripting project. You can get the sources and build it using these steps:

  1. svn checkout https://java.net/projects/Scripting
  2. cd $scripting/trunk/engines/javascript/lib
  3. drop Rhino js.jar into the above dir
  4. cd ../make
  5. ant clean all

The above step result in $scripting/trunk/engines/javascript/build/js-engine.jar

Using Rhino JSR-223 engine

You've two jars now: js.jar and js-engine.jar. You can put these two jars in your CLASSPATH. When creating script engine in your app, you need to use "rhino" as engine name.

Using Rhino jsr-223 engine from Java
import javax.script.*;

public class Main {
    public static void main(String[] args) throws Exception {
        ScriptEngineManager m = new ScriptEngineManager();
        // specifically look for "rhino" engine
        ScriptEngine engine = m.getEngineByName("rhino");
        System.out.println(engine.eval("33 + 232"));
    }
}

// compile above using

javac Main.java

// run it using

java -cp js-engine.jar:js.jar Main

You can also use jrunscript" in jdk8 along with this rhino based script engine:

Using jsr223 rhino engine with jrunscript
jrunscript -cp js-engine.jar:js.jar -l rhino
Overview
Content Tools
ThemeBuilder
  • No labels

Terms of Use
• License: GPLv2
• Privacy • Trademarks • Contact Us

Powered by a free Atlassian Confluence Open Source Project License granted to https://www.atlassian.com/software/views/opensource-community-additional-license-offer. Evaluate Confluence today.

  • Kolekti ThemeBuilder Powered by Atlassian Confluence 8.5.21
  • Kolekti ThemeBuilder printed.by.atlassian.confluence
  • Report a bug
  • Atlassian News
Atlassian
Kolekti ThemeBuilder EngineAtlassian Confluence
{"serverDuration": 274, "requestCorrelationId": "099dabe61bb9512d"}