Help debugging Jython installation

Caveat: Noobie to everything openHAB but learning.
Pi2/openHAB 1.71 - Demo working fine
Installed Jython at /opt/jython

java -jar /opt/jython/jython.jar -v

Takes about 10 seconds to execute and this is output:
import: ‘exceptions’ as org.python.core.exceptions in builtin modules
import: ‘sys’ as sys in builtin modules
import: ‘errno’ as org.python.modules.errno in builtin modules
import: ‘posix’ as org.python.modules.posix.PosixModule in builtin modules
import: ‘MemoryHistory’ as java class
import: ‘_sre’ as org.python.modules._sre in builtin modules
import: ‘_codecs’ as org.python.modules._codecs in builtin modules
import: ‘array’ as org.python.modules.ArrayModule in builtin modules
import: ‘_functools’ as org.python.modules._functools._functools in builtin modules
import: ‘StringBuilder’ as java class
import: ‘ByteBuffer’ as java class
import: ‘CharBuffer’ as java class
import: ‘Charset’ as java class
import: ‘IllegalCharsetNameException’ as java class
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot™ Client VM (Oracle Corporation)] on java1.8.0
Type “help”, “copyright”, “credits” or “license” for more information.


Maybe that’s normal but seems like a long time.

Here’s my script additions:
JYTHON_HOME="/opt/jython" ... JAVA_ARGS_DEFAULT="-Dosgi.clean=true \ -Dpython.home="$JYTHON_HOME" \ ...

And here’s my inside the scripts directory (copied from another user):
class TestRule(Rule):
def init(self):
self.timer = None

def getEventTrigger(self):
    return [
        TimerTrigger("*/5 * * * * ?")

def execute(self, event):
    def TimerFunc():
        oh.logInfo("TestRule", "TimerFunc")

    if not self.timer is None:
        oh.logInfo("TestRule", "cancel timer")

    oh.logInfo("TestRule", "start timer")		
    self.timer = oh.createTimer(, TimerFunc)

But nothing works and there’s nothing in the log file

I also added this to logbook.xml
<logger name="org.openhab.core.jsr223.internal.engine" level="DEBUG" />
and openhab is set to DEBUG

Any ideas?

If there’s nothing related to JSR223 in the log file (especially at DEBUG level) it seems like the JSR223 addon JAR might not not installed.

Thank you for the good suggestion. Sadly, I don’t think that’s the reason:
pi@raspberrypi:~ $ ls -l /usr/share/openhab/addons/ total 1020 -rwxr-xr-x 1 openhab openhab 19558 Aug 1 05:38 org.openhab.binding.http-1.7.1.jar -rwxr-xr-x 1 openhab openhab 10156 Aug 1 05:38 org.openhab.binding.ntp-1.7.1.jar -rwxr-xr-x 1 openhab openhab 325425 Jul 31 21:38 -rwxr-xr-x 1 openhab openhab 38729 Aug 1 05:39 org.openhab.core.jsr223-1.7.1.jar -rwxr-xr-x 1 openhab openhab 6163 Aug 1 05:40 org.openhab.persistence.exec-1.7.1.jar -rwxr-xr-x 1 openhab openhab 7386 Aug 1 05:40 org.openhab.persistence.logging-1.7.1.jar -rwxr-xr-x 1 openhab openhab 624538 Aug 1 05:40 org.openhab.persistence.rrd4j-1.7.1.jar

Did you make any changes to I also had some trouble getting Jython running which are documented here: JSR223 - Can't find jython

symlink is there:
pi@raspberrypi:~ $ sudo ls -la /usr/share/openhab/lib/ lrwxrwxrwx 1 root root 22 Dec 16 15:00 jython.jar -> /opt/jython/jython.jar

I modified as in my first post in accordance with the Wiki.

Baffled why I don’t even get the logging you did in you post. Searching for jsr finds nothing.

I remember there being some issues with the 1.7.1 jsr223 jar file, so I installed a 1.8-SNAPSHOT build from cloudbees:

It’s now finding the jar because I get this in log file:

21:36:24.504 [DEBUG] [j.internal.Jsr223CoreActivator:33 ] - Registered 'jsr223' scripting-engine

but the rule never executes.
Do I have to put something somewhere else? I’m assuming when openHAB logs
21:25:51.389 [INFO ] [o.c.j.i.e.scriptmanager.Script:84 ] - Loading Script
then openHAB found the rule.

That means it found the rule file, but not necessarily the engine to run the rule.

When openHAB starts you should see the JSR223 engines being registered:

 2015-12-07 12:47:12.033 [INFO ] [o.o.c.j.i.e.s.ScriptManager   ] - Available engines:
 2015-12-07 12:47:12.084 [INFO ] [o.o.c.j.i.e.s.ScriptManager   ] - Oracle Nashorn
 2015-12-07 12:47:12.085 [INFO ] [o.o.c.j.i.e.s.ScriptManager   ] - jython

If you don’t see Jython being listed, then the jython JAR file was not found. This is usually a classpath issue. When the rule file is loaded, you’ll see something like:

2015-12-07 12:47:12.093 [INFO ] [o.c.j.i.e.scriptmanager.Script] - Loading Script
2015-12-07 12:47:28.466 [INFO ] [o.c.j.i.e.scriptmanager.Script] - EngineName: jython
2015-12-07 12:47:35.001 [INFO ] [o.o.c.j.i.e.s.ScriptManager   ] - Engine found for File:

If the engine cannot be found, you’ll see something like:

2015-12-07 12:47:37.499 [INFO ] [o.c.j.i.e.scriptmanager.Script] - Loading Script
2015-12-07 12:47:37.503 [WARN ] [o.o.c.j.i.e.s.ScriptManager   ] - No Engine found for File:

I agree it must be a class path issue but I followed the wiki instructions and it’s in the class path.

Can you explain what this means? “Call the org.eclipse.equinox.launcher.Main”

Rather than call the jar file with the -jar option, I add that jar to the classpath and add org.eclipse.equinox.launcher.Main to the end of the command line, like the example in the wiki:

java \
-Dpython.home="$JYTHON_HOME" \
-Dosgi.clean=true \
-Declipse.ignoreApp=true \
-Dosgi.noShutdown=true  \
-Djetty.port=$HTTP_PORT  \
-Djetty.port.ssl=$HTTPS_PORT \
-Djetty.home=.  \
-Dlogback.configurationFile=configurations/logback.xml \
-Dfelix.fileinstall.dir=addons -Dfelix.fileinstall.filter=.*\\.jar \
-Djava.library.path=lib \ \ \
-Dequinox.ds.block_timeout=240000 \
-Dequinox.scr.waitTimeOnBlock=60000 \ \
-Djava.awt.headless=true \
-cp $cp org.eclipse.equinox.launcher.Main $* \

I’ve been meaning to post my updated startup script in a bug report, but haven’t got around to it yet.

Started over with a clean openhab install and python now works.
Also used this github_test
A lot of gotchas for me which others may not notice.
This will help in porting much of my python code.

Glad it’s working for you!

Thanks much for your kind assistance.
It seems when I make a change to my Python code {openhab}scripts/*.py that I have to restart the server. Is there anyway to reload the changed script for execution without the length process of restarting?

OH normally reloads the scripts/*.py files when it detects they have changed. Are you monitoring the log files closely?

Yes to DEBUG monitoring of logs.
If I change a py file, I’ll see this in logs but then it never executes again.
2015-12-21 15:22:57.901 [DEBUG] [.c.j.i.e.s.ScriptUpdateWatcher] - ENTRY_DELETE: 2015-12-21 15:22:57.906 [DEBUG] [.j.i.engine.RuleTriggerManager] - Removed scheduled cron job '$UpdateThermostats$1@80bf48#0 0/38 * 1/1 * ? *'
For example, say I simply change the CRON frequency from 38 minutes to 2 minutes. It will never execute again until restart. (Just to be clear, the script will run every 2 minutes on next restart.)

Try running the command: touch I’ve found that the JSR223 binding is a little less forgiving of the file saving dance that editors such as vim do when writing to a file than the normal OH rules engine.

Thanks so much, Rob! It’s odd that it noticed the file changed and deleted the entry and never reloaded but the touch command saves me a lot of time over restarting the server.

Update: touch causes it to load and execute but not always with the changes. For example, I changed some DEBUG log statements by commenting them out with # and after a save and touch, they still executed. Maybe there’s some kind of samba problem for me.