Example code to Test rhino-runtime-1.7.14.jar

Q

How to test rhino-runtime-1.7.14.jar?

✍: FYIcenter

A

You can write a simple Java program, RhinoRuntimeTest.java, to test rhino-runtime-1.7.14.jar:

// Copyright (c) FYIcenter.com
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
public class RhinoRuntimeTest {
  public static void main(String args[]) {
    Context cx = Context.enter();
    try {
      Scriptable scope = cx.initStandardObjects();
      String js = 
        "function p2k(p) {return p*0.453592;} '5 pound = '+p2k(5.0)+' kilo';";
      Object result = cx.evaluateString(scope, js, "<cmd>", 1, null);
      System.err.println(Context.toString(result));
    } finally {
      Context.exit();
    }
  }
}

6. Run the test program, RhinoRuntimeTest.java:

\fyicenter> java -cp rhino-runtime-1.7.14.jar RhinoRuntimeTest.java
5 pound = 2.26796 kilo

 

Download Rhino JavaScript rhino1_7R5.zip

Rhino JavaScript Java Library Source Code

Download and Review Rhino JavaScript Java Library

⇑⇑ FAQ for Rhino JavaScript Java Library

2023-01-23, 2366👍, 3💬