Need help with JSR223 setup in Eclipse IDE (Windows)

I am trying to setup JSR223 scripting in Eclipse. I found https://github.com/eclipse-archived/smarthome/wiki/Scripted-Rule-Support, but I fear those pointers are for the old build style.

I have org.openhab.core.automation.module.script.rulesupport and org.openhab.core.automation.module.script in the Run Requirements - not sure if those are the right ones for the JSR223 engine?

For simplicity I started with Javascript as it doesn’t require any additional setup (though I am really looking to setup Jython scripting in the end).

I placed a sample file demo.js in conf/automation/jsr223:
Java.type(“org.slf4j.LoggerFactory”).getLogger(“org.openhab.core.automation.test”).debug(“HelloWorld”);

I see
21:38:14.242 [main] DEBUG o.o.c.a.m.s.i.ScriptEngineManagerImpl:77 - Initialized a generic ScriptEngineFactory for Oracle Nashorn (1.8.0_191): supports ECMAScript (ECMA - 262 Edition 5.1) with file extensions [js], names [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], and mimetypes [application/javascript, application/ecmascript, text/javascript, text/ecmascript]
in the logs, but no indication that my demo.js ran. Any ideas where to look next? Thank you very much!

  • Platform information:
    • OS: Windows 10
    • openHAB version: 2.5.4-SNAPSHOT
    • Eclipse 2019-06

What are you looking to debug? I usually just make changes, using extra debugging, compile, and then add the jar to an existing install. I did post some instructions in GH though… I’ll need to find them and post back.

Found it

You’ll need to add these directories to the demo app and then add this line to the /launch/app/app.bndrun file in openhab-distro…

-runvm: -Xbootclasspath/a:${.}/runtime/conf/automation/jython/jython-standalone-2.7.0.jar,-Dpython.home=${.}/runtime/conf/automation/jython,-Dpython.path=${.}/runtime/conf/automation/lib/python

You’ll also need all of the org.openhab.core.automation packages added to runrequires and runbundles. You will also need to add loggers to the logback.xml to be able to log from org.openhab.core.automation and rules. I don’t plan to update the helper libraries to be compatible with OH 3.0 until it’s ready for testing, so they won’t work yet.

Thank you for the pointers Scott. Turns out in the end that my problem was https://github.com/openhab/openhab-core/issues/841. All set now.

1 Like