Installing jython for JSR233 - update on wiki

I’ve just got jython working on both Windows and Linux, and some bits are a little bit different to the Wiki. I’m using Java 8, Jython 2.7.0 and a recent snapshot of OH1.8.0 on Windows 7 and OpenSuse 13.2

I found that (at least on Windows):

  1. The Python scripts must be in the scripts directory
  2. The extension of the script file must be “'py”

And on Linux, symlinking to the Jython library as suggested in the wiki didn’t work for me, so I added the link into the classpath in the startup script

Here’s the complete start.bat:

@echo off

:: set path to eclipse folder. If local folder, use ‘.’; otherwise, use c:\path\to\eclipse
set ECLIPSEHOME=server

:: set ports for HTTP(S) server
set HTTP_PORT=8080
set HTTPS_PORT=8443

set JYTHON_HOME=C:\jython2.7.0

:: get path to equinox jar inside ECLIPSEHOME folder
for /f “delims= tokens=1” %%c in (‘dir /B /S /OD %ECLIPSEHOME%\plugins\org.eclipse.equinox.launcher_*.jar’) do set EQUINOXJAR=%%c

:: start Eclipse w/ java
echo Launching the openHAB runtime…
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 -Dorg.osgi.framework.bundle.parent=ext -Dequinox.ds.block_timeout=240000 -Dequinox.scr.waitTimeOnBlock=60000 -Djava.awt.headless=true -cp %JYTHON_HOME%\jython.jar;%EQUINOXJAR% org.eclipse.equinox.launcher.Main % -console



cd dirname $0

# set path to eclipse folder. If local folder, use '.'; otherwise, use /path/to/eclipse/

# set ports for HTTP(S) server - temporarily non-default


# get path to equinox jar inside $eclipsehome folder
cp=$(find $eclipsehome -name “org.eclipse.equinox.launcher_*.jar” | sort | tail -1);

echo Launching the openHAB runtime…
-Dfelix.fileinstall.dir=addons -Dfelix.fileinstall.filter=.\.jar
-cp $JYTHON_HOME/jython.jar:$cp org.eclipse.equinox.launcher.Main $


If you want to start the Linux script in background mode, basically add one line:

-cp $JYTHON_HOME/jython.jar:$cp org.eclipse.equinox.launcher.Main $*
> run.log 2>&1 &

It’s not Windows-specific. This is documented on the JSR223 wiki page, but it’s easy to overlook.

And on Linux, symlinking to the Jython library as suggested in the wiki didn't work for me

The symlink to the jython.jar from the addons directory works well for me on Raspberry Pi (raspbian/wheezy).

Hi guys!

I’m updating my Xtend rules to Jython and so far everything is working fine, but I have one question about the messages that appear every time a rule is executed. One of my rules is being executed every 10 seconds (I established a telnet connection to my router and check the list of connected devices to detect presence at home) and the following messages is written to the log file:

17:44:00.000 INFO o.o.c.j.i.e.TimeTriggerJob[:35]- TimeTrigger for rule: org.python.proxies.builtin$LocationRules$48@4ed68c4e, scriptName:

Is there any way to disable this message? The Xtend rules don’t write anything unless you specified it using the logger command…

Many thanks for your help!!

Best regards,


you can add the following to your configurations/logback.xml:

<logger name="org.openhab.core.jsr223.internal.engine" level="ERROR" />

1 Like

Many thanks for your replay Simon, it works perfectly!!

Hi guys!

As a former poster in this topic, I was a user of the JSR233 engine (using jython), but now I need some help installing the JSR223 addon in an apt-get installation of openHAB 1.8.1 :pensive: In the Wiki page it is said that the jython.jar file should be "symlink"ed to /opt/openhab/lib/, so in my case I have made a symlink to /usr/share/openhab/lib. I suppose that this is correct, but is it? My problems begin with the changes that need to be made in file.

Where should I edit the “cp=$(echo lib/.jar | tr ’ ’ ‘:’):$(find $eclipsehome -name "org.eclipse.equinox.launcher_.jar” | sort | tail -1);" line?

  • In /etc/default/openhab as JAVA_ARGS? As OPEHAB_ARGS?
  • In the /etc/init.d/openhab file? In that file I can see a “LAUNCHER=ls ${OPENHAB_DIR}/server/plugins/org.eclipse.equinox.launcher_*.jar” line, but I don’t understand how should I change it…
  • In /usr/share/openhab/bin/
  • Any other file?

Many thanks for reading my message and I’m really looking forward to continue playing with jython. I will update the wiki page accordingly once I have it working again :wink:

Thanks again and best regards,


@riturrioz Did you find an answer to your question? I’m moving to an apt-get installation and have similar questions. I thought I’d ask here before I rediscover the answer the hard way.

Hi @steve1!

Well… not so much, I have it working but I doubt that what I have done is the best approach. This is what works for me:

  • Symlink the “/opt/jython/jython.jar” file to “/usr/share/openhab/lib/jython.jar”
  • Edit the following lines in the “/etc/init.d/openhab” file:
    • Add CP=$(echo ${OPENHAB_DIR}/lib/.jar | tr ’ ’ ‘:’):$(find ${OPENHAB_DIR} -name "org.eclipse.equinox.launcher_.jar" | sort | tail -1); below the LAUNCHER=‘ls …’; line.
    • Add -Dpython.home="/opt/jython" \ to the JAVA_ARGS_DEFAULT list.
    • Comment the -jar ${LAUNCHER} \ line
    • Add -cp ${CP} org.eclipse.equinox.launcher.Main $* \ below the -jar ${LAUNCHER} \ line

But I still don’t understand the existence of the file (/usr/share/openhab/bin folder) :confused:

I hope it works for you steve!

Best regards,


Interesting. I did something similar but I had to change the /usr/share/openhab/bin/ file. I’m guessing it depends on whether the linux distro is using systemd or not (mine is using it).

I worked it out without a symlink. So this should work in your case, too.
First I added JYTHON_HOME="/opt/jython2.7.0" in the script that started openhab.

As call parameters I added the following:

-cp $JYTHON_HOME/jython.jar:$cp org.eclipse.equinox.launcher.Main $

Please be aware, that for the last line replaces the orignal call:

-jar $cp

I’m doing something similar. However, I have several different JAR files in the lib directory so I’m setting up the classpath using…

export CLASSPATH="`echo $OPENHAB_DIR/lib/*.jar | tr ' ' ':'`:$LAUNCHER"

That way it picks up all the JARs in the lib directory (like sigar.jar for the system info binding, for example) and I don’t need to use the -cp argument since java will use the CLASSPATH environment variable.

I also add -Dpython.path="$OPENHAB_CONF_DIR/lib/python" to the JAVA_ARGS_DEFAULT. This adds the specified path(s) to Python’s sys.path. I use that for loading Jython modules that are located outside of the script directory. I like this better than setting up sys.path within each script.

I am trying to use the oh.getLogger in my library but it seems not to be recognized.

javax.script.ScriptException: NameError: name 'oh' is not defined in <script> at line number 8

What can I do so this works?

(Copied from other thread…) The Openhab class is automatically imported into rule scripts, but you must explicitly import it into other Python modules. If you look at, you see some sample imports for many OH types.

1 Like

can someone help me get this working on an apt-get install? i’m having zero luck after following the wiki…it finds jython but my scripts are not working whatsoever. it either runs once and then hangs, or runs about 20 times within 5 seconds and then hangs…

Rather than fragmenting the discussion maybe we should continue it in the original topic you created?