Problems with jsr223 binding (javascript)


I’m trying to get the jsr223 binding working working with the built in javascript engine. I installed the package from the apt repo and added the missing jsr223engine.xml to the OSGI-INF directory of the jar file. I also added -Dorg.osgi.framework.bundle.parent=ext to my java options.

The binding is starting up and looking for scripts, however it throws an error when loading my test script:

2015-10-06 21:24:45.026 [INFO ] [o.c.j.i.e.scriptmanager.Script] - Loading Script test_rules.js
2015-10-06 21:24:45.041 [ERROR] [o.o.c.j.i.e.s.ScriptManager   ] - script exception
javax.script.ScriptException: TypeError: is not a function, it is object. (<Unknown source>#5) in <Unknown source> at line number 5
        at com.sun.script.javascript.RhinoScriptEngine.eval( ~[na:1.7.0_79]
        at javax.script.AbstractScriptEngine.eval( ~[na:1.7.0_79]
        at org.openhab.core.jsr223.internal.engine.scriptmanager.Script.loadScript( ~[bundlefile:na]
        at org.openhab.core.jsr223.internal.engine.scriptmanager.Script.<init>( ~[bundlefile:na]
        at org.openhab.core.jsr223.internal.engine.scriptmanager.ScriptManager.loadScript( [bundlefile:na]
        at org.openhab.core.jsr223.internal.engine.scriptmanager.ScriptManager.scriptsChanged( [bundlefile:na]
        at [bundlefile:na]
        at [na:1.7.0_79]
Caused by: TypeError: is not a function, it is object. (<Unknown source>#5)
        at ~[na:1.7R4]
        at ~[na:1.7R4]
        at ~[na:1.7R4]
        at ~[na:1.7R4]
        at ~[na:1.7R4]
        at ~[na:1.7R4]
        at ~[na:1.7R4]
        at ~[na:1.7R4]
        at ~[na:1.7R4]
        at ~[na:1.7R4]
        at com.sun.script.javascript.RhinoScriptEngine$1.superDoTopCall( ~[na:1.7.0_79]
        at com.sun.script.javascript.RhinoScriptEngine$1.doTopCall( ~[na:1.7.0_79]
        at ~[na:1.7R4]
        at ~[na:1.7R4]
        at ~[na:1.7R4]
        at com.sun.script.javascript.RhinoScriptEngine.eval( ~[na:1.7.0_79]
        ... 7 common frames omitted

The test_rules.js script is as follows:

'use strict';

var jsTest = new Rule(){
    getEventTrigger: function(){
        oh.logDebug("getEventTrigger", "self:"+this);
        return [
            new TimerTrigger("0/15 * * * * ?")
    execute: function(event){
        oh.logError("Hello from javascript");
 function getRules(){return new RuleSet([jsTest]);}

Any help appreciated!

Thanks in advance.

I haven’t used Javascript with the JSR223 binding, but my understanding is that it only supports Nashorn Javascript (Java 8). It looks like you are using an older version of Java using Rhino instead.

Sorry for the late reply, haven’t had chance to get back to this.

That does appear to be the problem, thanks!