JRule, Scala, and pre-compiled alternative: How to import the JRule libraries and pre-compile the rules?

Hi, everyone.

I started experimenting with Scala, sbt, and Visual Studio + Metals. I’m wondering how to import the JRule classes. Should I clone the JRule source code into my code and import the classes wherever required, or should I somehow add the Jar to my /lib folder?
I don’t see any Jar provided in GitHub.

Connected to the previous doubt, I’m also wondering if when compiling the Uber Jar I should also include the JRule libraries (as if they were part of my code) or if there is no need and the ones installed in OH by the add-on should be used.

Thanks for any help!

Take a look here for a sample project; GitHub - seaside1/jrule: openHAB Java Rules Engine

TLDR: Copy these 2 jar files to your local project/maven repo and depend on them;

Disclaimer: I write my rules in Java using IntelliJ, so no overlap with your listed stack.

Thanks, @seime. Thanks to your guidance I made it work after struggling for a while with Metals.

Now I’m struggling with this import:

import org.openhab.automation.jrule.generated.xxxx

The compiler complains that generated is not a member of jrule, even though I deployed jrule-generated.jar to the dependencies folder (/lib), just like jrule.jar and openhab-core.jar.
I can find all the members of the other 2 jars, but not the ones of jrule-generated.jar. The file has 177 KB

I decompiled the jrule-generated.jar and found that the package conformed to org.openhab.automation.jrule.generate.xxxx, so I deleted all the caches in the project, imported the project again into Visual Studio Code, and the jar was recognized.

There are just two minor things left that I think I can sort out by testing:

  1. The from and to arguments expect a String and the compiler complains when I pass the JRuleOnOffValue.ON/OFF values, so I hope they just work by passing “ON” or “OFF”

  2. I’m still not sure if the pre-compiled jar should also include the jrule-generated.jar, jrule.jar, and openhab-core.jar libraries that I downloaded.

The rule successfully ran after packaging the project without the dependencies and deploying it to /rules-jar in OH!

Hello Scala World! :slight_smile:

They are availble on the server already, and are just needed by the compiler.

Congrats on creating the possibly first Scala rule to run on JRule! :slight_smile:

I’m not the first one, I was probably convinced by the first person to do it :smiley:

1 Like