[Windows] All OH logs stop when Jython is in the classpath

I think @rlkoshak may be interested hearing about that one! Where did you get the ScriptEngines from? I’ve been curious to try a recent version of Kotlin.

We should start a new thread! One thing that I’d really like to discuss with you about the OH3 UI is the ability to have multiple paths through a UI rule. I think the functionality might already be in the framework, at least partially, but if it is not, it should get implemented. I expect this would have a huge impact to the rule UI.

Very exciting stuff
Yes please do start a new thread

I’m more interested in Scala or Clojure but IIRC getting JRuby to run in the first place wasn’t the problem. It was building that bridge between Ruby and OH that became a challenge. See Using JRuby for rules for the latest (2017) I’ve seen it discussed.

I made some more attempts since then and got a bit further at least. Seems the scriptExtension and other scope values is global values in Ruby, which means they need to be prepended with a $, so using $scriptExtension.importPreset() works at least. I never got through to create rules though, had problems subclassing SimpleRule, and creating rules using the RuleRegistry was too complicated at the time, but I think it should work. @ysc have you tried any of that?

I noticed this too but that’s the case if you run Ruby 2.3.x i.e. JRuby 9.1.x (downloaded from Downloads — JRuby.org). If you run the latest JRuby 9.2.x which is Ruby 2.5 then you don’t need the dollar signs anymore.

Also I managed to at least get the logging working from a scripted rule action - JRuby seems to use its own ClassLoader, probably to allow things like described in CallingJavaFromJRuby · jruby/jruby Wiki · GitHub, you can however get hold of the EquinoxClassLoader from one of the objects in the script scope using reflection, then invoke the getLogger static method like this:

puts ir.java_class.class_loader.inspect
loggerFactoryClass = ir.java_class.class_loader.load_class('org.slf4j.LoggerFactory')
method = loggerFactoryClass.getMethod('getLogger', java.lang.String)
logger = method.invoke(nil, 'jsr223.ruby')
logger.debug('Log from Ruby!')
#<Java::OrgEclipseOsgiInternalLoader::EquinoxClassLoader:0x68f8e05c>                                                  
08:39:22.454 [DEBUG] [jsr223.ruby                          ] - Log from Ruby!       

Pretty ugly and I don’t know if it would work in a .rb in the automation folder but it could probably be streamlined to load any class from OH. Maybe there’s a way to tell JRuby to use the Equinox class loader instead, but I didn’t find it.

Actually Kotlin doesn’t work at all :laughing: It appears to register the script engine since it’s in the list but when I try to execute a script action with some Kotlin code this is what I get:

[ERROR] [ript.internal.ScriptEngineManagerImpl] - ScriptEngine for language 'text/x-kotlin' could not be found for identifier: d4889621-ddea-454a-b33b-5f2030ed4637

I got the .jars from there: Release 1.3.50 · JetBrains/kotlin · GitHub

1 Like

@5iver and @ysc, when I initially loaded M4 on my Win10 machine (without @ysc 's workaround, but following @5iver 's instructions for start.bat, etc), it broke the logging/jython just as it did back in M2. I then noticed this workaround ([Windows] All OH logs stop when Jython is in the classpath) and decided to give it a try with 2.5.0M4. It does seem to help, but doesn’t get jython fully working. I get logging working again, and everything seems to load/initialize except jython scripts in any folders. If I “touch” a script (take 000_startup_delay.py for example) it will say "Loading script ‘python/core/components/000_startup_delay.py’, but that is it. Nothing else happens. I can go through and try to load each of them, but the rules don’t run. It was working flawlessly in 2.4 stable with setenv.bat file to what it is in 2.5 (per @5iver’s post [Windows] Using EXTRA_JAVA_OPTS, and then adding the required line to my start.bat.)

Any ideas?

This is another bug for Windows, but possibly evolved some… [Windows] All OH logs stop when Jython is in the classpath - #3 by 5iver

Yes, I’m very familiar with that issue, and I was hoping after waiting a few months that maybe it had been solved, but something definitely got better after applying this fix:

I wonder if @ysc saw similar behavior as I did and maybe had to do something else to get it totally working.

Just an update, I forgot to update org.ops4j.pax.logging.cfg with all of the jython logging stuff, so that made some of the logging look more normal, and I can now see that jython is working, however NOTHING gets loaded automatically at startup. None of my jython rules scripts work until I “touch” them (change 1 character and re-save), and none of the core.components scripts auto-load.

I only use openHAB on Windows for dev/test purposes, haven’t tested Jython with M4 yet but when I do I’ll be sure to check that. I guess it’s probably still

or a related issue.

Hello,

I use M4 on windows10 and I’m struggling to start NGRE Rule engine.
Now I managed to work “Hello world” on Java.
Phyton: any core.x module load give importerror: “ImportError: No module named core in at line number xx”
Groovy: nothing happens

I installed based on https://openhab-scripters.github.io/openhab-helper-libraries/Getting%20Started/Installation.html and i copied jython standalone runtime\lib\boot instead.
Example files are renamed.
But here I can’t find why modules are not loaded.

Are you s sure you copied the Helper Libraries to the right folder? The contents if the Core folder (automation on down) needs to be copied to $OH_CONF. You don’t copy the whole helper library over.

Here is my automation library:


only /core/ folder copied. Path: c:/openhab2/conf/automation it is on windows10.

Here is my ruleengine.log during a startup and I try to load one .py rule after startup:
ruleengine.log (27.0 KB)

Have you restarted OH? People have reported this error when Jython is not installed correctly. Did you modify EXTRA_JAVA_OPTS with the python.home and python.path? You still need these even if you bypass the bootclasspath by putting the Jython jar in /runtime/bin/boot.

This is my startup.bat file:


I have added the same to sh.bat as my Openhab runs as a service.
I can add as an windows enviroment variable instead.
I have tried it before but there was no difference but it was before I have changed the loacation of Jython standalone file. Sorry I have tried many variation and that’s why I ask some help. So I welcome any suggestion as I think I have a tiny bug somwhere. OH was restared after each change. If you suggest I can do it more time.

I just looked at your log and Jython is starting. What do you have under C:\openhab2\conf\automation\lib\python? Did you setup your configuration.py?

Here is the path and the content:

That looks good. I think it has something to do with your EXTRA_JAVA_OPTS or permissions. What happens if you start OH manually?

This is the Karaf Console:


log files of openahb.log and ruleengine.log:
ruleengine_201911061945.log (36.4 KB)
It does not load any rules from automation folders just when I copy it there while Openhab runs. Result is the same:
2019-11-03 19:46:48.702 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language ‘py’ with identifier: file:/C:/openhab2/conf/automation/jsr223/python/personal/owm_daily_forecast.py

2019-11-03 19:46:48.983 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script ‘file:/C:/openhab2/conf/automation/jsr223/python/personal/owm_daily_forecast.py’: ImportError: No module named core in at line number 104

I also encounter the same problem as https://community.openhab.org/u/kovacsi2899 (Windows 10, last SNAPSHOT, Jython, Openhab runs as a service, …)
Thanks in advance