First of all, you need to start your global scope (initialize the entire standard javascript object, functions, etc.), and then add your function to this area, as Hannes Wannofer wrote.
Context cx = Context.enter(); //enter rhino context - bind context with current thread Scriptable globalScope= cx.initStandardObjects(); //init js standard object in global scope globalScope.defineProperty("myNativeFunction", new MyGlobalNativeFunction(), ScriptableObject.DONTENUM);
and what is he.
Now to call this function, call:
Object result = cx.evaluateString(globalScope, "myNativeFunction()", "<cmd>", 1, null);
See the rhino introduction tutorial for more information.
source share