Where should I put a .jar for using it into rule?

Hi
I want to use jfuzzylite-5.0 jar file .I tried creating a folder and put the jar in \server\configuration\org.eclipse.osgi\bundles. Then I tried put it in \distribution-1.8.3-runtime\server\plugins but neither of these two ways work.

Also my import statements is

import com.fuzzylite.*
import com.fuzzylite.FuzzyLite
import com.fuzzylite.Op
import com.fuzzylite.defuzzifier.Centroid
import com.fuzzylite.imex.FldExporter
import com.fuzzylite.norm.s.Maximum
import com.fuzzylite.norm.t.Minimum
import com.fuzzylite.rule.Rule
import com.fuzzylite.rule.RuleBlock
import com.fuzzylite.term.Trapezoid
import com.fuzzylite.term.Triangle
import com.fuzzylite.variable.InputVariable
import com.fuzzylite.variable.OutputVariable

In lines 8-9 I am importing rule which is a keyword
http://www.eclipse.org/xtend/documentation/202_xtend_classes_members.html#imports
In the documentation says to use this “^” but doesn’t say where should I put it. Has anynone any idea??

The import is like this

import com.fuzzylite.^rule.Rule
import com.fuzzylite.^rule.RuleBlock

Openhab designer just needed some more time to stop showing the error

I think (emphasis on think) you can drop the jar file into the addons folder and those classes will be added to the classpath. This is for OH 1.8.x. I’m not sure how it works in OH 2.

NOTE: The rules language is not Xtend, it is very similar to it but it is not the same. For example, you cannot create classes or arrays in the rules language. Always check the Rules wiki page first and the Xtend docs second when looking for references.

To answer your specific question, all imports go at the top of your .rules file.

No it doesn’t work either I put the jar into the addons folder. It posts

 2016-07-01 21:21:18.746 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ' fuzzy logic'
java.lang.NullPointerException: null

Is this because of the jar file right ??
Here is my code which is all red by openhab design and pops errors like these
Couldn’t resolve reference to JvmType ‘Engine’.

  • Couldn’t resolve reference to JvmConstructor ‘Engine’

    rule " fuzzy logic"
    when
    Item PMV changed or
    Item Temperature_thermistor changed
    then

      var Number PMV_value=(PMV.state as DecimalType)
      var Number Tout_value=(Temperature_thermistor.state as DecimalType) 
    

    var Engine engine = new Engine()
    engine.setName(“PMV-Controller v3”)

    var InputVariable inputVariable1 = new InputVariable();
    inputVariable1.setEnabled(true)
    inputVariable1.setName(“PMVvalue”)
    inputVariable1.setRange(-3.000, 3.000)
    inputVariable1.addTerm(new Trapezoid(“NE”, -9.350, -5.150, -2.500, -1.650))
    inputVariable1.addTerm(new Trapezoid(“SNE”, -2.850, -1.850, -0.850, -0.150))
    inputVariable1.addTerm(new Trapezoid(“ZERO”, -1.350, -0.400, 0.400, 1.350))
    inputVariable1.addTerm(new Trapezoid(“SPO”, 0.150, 0.850, 1.850, 2.850))
    inputVariable1.addTerm(new Trapezoid(“PO”, 1.650, 2.850, 3.150, 4.350))
    engine.addInputVariable(inputVariable1);

    var InputVariable inputVariable2 = new InputVariable();
    inputVariable2.setEnabled(true);
    inputVariable2.setName(“Tout”);
    inputVariable2.setRange(0.000, 40.000);
    inputVariable2.addTerm(new Trapezoid(“VCOLD”, -9.000, 0.000, 9.000, 15.000));
    inputVariable2.addTerm(new Trapezoid(“MCOLD”, 10.000, 13.000, 18.000, 20.000));
    inputVariable2.addTerm(new Trapezoid(“OK”, 17.000, 20.000, 24.000, 26.000));
    inputVariable2.addTerm(new Trapezoid(“MHOT”, 23.000, 25.000, 28.000, 30.000));
    inputVariable2.addTerm(new Trapezoid(“VHOT”, 28.000, 29.000, 40.000, 60.000));
    engine.addInputVariable(inputVariable2);

    var OutputVariable outputVariable1 = new OutputVariable()
    outputVariable1.setEnabled(true)
    outputVariable1.setName(“HVACSETPOINTCHANGE”)
    outputVariable1.setRange(-3.000, 3.000)
    outputVariable1.fuzzyOutput().setAccumulation(new Maximum())
    outputVariable1.setDefuzzifier(new Centroid(200))
    outputVariable1.setDefaultValue(Double.NaN)
    outputVariable1.setLockValidOutput(false)
    outputVariable1.setLockOutputRange(false)
    outputVariable1.addTerm(new Trapezoid(“NE”, -4.000, -3.000, -2.000, -1.500))
    outputVariable1.addTerm(new Trapezoid(“SNE”, -2.000, -1.500, -0.750, 0.000))
    outputVariable1.addTerm(new Trapezoid(“ZERO”, -1.000, -0.500, 0.500, 1.000))
    outputVariable1.addTerm(new Trapezoid(“SPO”, 0.000, 0.750, 1.500, 2.000))
    outputVariable1.addTerm(new Trapezoid(“PO”, 1.500, 2.000, 3.000, 4.000))
    engine.addOutputVariable(outputVariable1)

    var OutputVariable outputVariable2 = new OutputVariable()
    outputVariable2.setEnabled(true)
    outputVariable2.setName(“Mechanicalventilationchange”)
    outputVariable2.setRange(-100.000, 100.000)
    outputVariable2.fuzzyOutput().setAccumulation(new Maximum())
    outputVariable2.setDefuzzifier(new Centroid(200))
    outputVariable2.setDefaultValue(Double.NaN)
    outputVariable2.setLockValidOutput(false)
    outputVariable2.setLockOutputRange(false)
    outputVariable2.addTerm(new Trapezoid(“NE”, -150.000, -100.000, -80.000, -60.000))
    outputVariable2.addTerm(new Trapezoid(“SNE”, -60.000, -50.000, -30.000, -10.000))
    outputVariable2.addTerm(new Trapezoid(“ZERO”, -20.000, -10.000, 10.000, 20.000))
    outputVariable2.addTerm(new Trapezoid(“SPO”, 10.000, 30.000, 50.000, 60.000))
    outputVariable2.addTerm(new Trapezoid(“PO”, 60.000, 80.000, 100.000, 150.000))
    engine.addOutputVariable(outputVariable2)

    var RuleBlock ruleBlock = new RuleBlock()
    ruleBlock.setEnabled(true)
    ruleBlock.setName("")
    ruleBlock.setConjunction(new Minimum())
    ruleBlock.setDisjunction(new Maximum())
    ruleBlock.setActivation(new Minimum())
    ruleBlock.addRule(Rule.parse(“if PMVvalue is NE and Tout is VCOLD then HVACSETPOINTCHANGE is PO and Mechanicalventilationchange is NE”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is NE and Tout is MCOLD then HVACSETPOINTCHANGE is SPO and Mechanicalventilationchange is SNE”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is NE and Tout is OK then HVACSETPOINTCHANGE is SPO and Mechanicalventilationchange is SPO”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is NE and Tout is MHOT then HVACSETPOINTCHANGE is ZERO and Mechanicalventilationchange is PO”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is NE and Tout is VHOT then HVACSETPOINTCHANGE is ZERO and Mechanicalventilationchange is PO”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is SNE and Tout is VCOLD then HVACSETPOINTCHANGE is SPO and Mechanicalventilationchange is SNE”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is SNE and Tout is MCOLD then HVACSETPOINTCHANGE is SPO and Mechanicalventilationchange is ZERO”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is SNE and Tout is MHOT then HVACSETPOINTCHANGE is ZERO and Mechanicalventilationchange is SPO”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is ZERO then HVACSETPOINTCHANGE is ZERO and Mechanicalventilationchange is ZERO”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is SPO and Tout is VCOLD then HVACSETPOINTCHANGE is ZERO and Mechanicalventilationchange is SPO”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is SPO and Tout is OK then HVACSETPOINTCHANGE is SNE and Mechanicalventilationchange is ZERO”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is SPO and Tout is MHOT then HVACSETPOINTCHANGE is SNE and Mechanicalventilationchange is SNE”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is SPO and Tout is VHOT then HVACSETPOINTCHANGE is NE and Mechanicalventilationchange is NE”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is PO and Tout is VCOLD then HVACSETPOINTCHANGE is NE and Mechanicalventilationchange is PO”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is PO and Tout is MCOLD then HVACSETPOINTCHANGE is SNE and Mechanicalventilationchange is PO”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is PO and Tout is OK then HVACSETPOINTCHANGE is SNE and Mechanicalventilationchange is SNE”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is PO and Tout is MHOT then HVACSETPOINTCHANGE is SNE and Mechanicalventilationchange is NE”, engine))
    ruleBlock.addRule(Rule.parse(“if PMVvalue is PO and Tout is VHOT then HVACSETPOINTCHANGE is NE and Mechanicalventilationchange is NE”, engine))
    engine.addRuleBlock(ruleBlock)

    inputVariable1.setInputValue(PMV_value.doubleValue)
    inputVariable2.setInputValue(Tout_value.doubleValue);
    engine.process();

    postUpdate(HVACSETPOINTCHANGE,Op.str(outputVariable1.getOutputValue()))
    postUpdate(Mechanicalventilationchange,Op.str(outputVariable2.getOutputValue()))

    end

No. You would get the equivalent of a Not Found type exception. NullPointerException is unfortunately a catch all exception in the Rules DSL and can mean you have an uninitialized variable, incompatible data types, it something like that.

Add some log statements to narrow down in the rule where the error is being generated.

The good news is I think it imported the jar file for you at least.

Unfortunately Designer is not able to support this party jars (as far as I’ve been able to tell) so you will always have that error appear in Designer on every line that uses a class from the library.

I don’t think it had imported the jar file cause it posts this in the log file

2016-07-03 17:28:24.307 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ' fuzzy logic'
java.lang.NullPointerException: null
    at org.eclipse.xtext.common.types.util.JavaReflectAccess.getRawType(JavaReflectAccess.java:107) ~[na:na]
    at org.eclipse.xtext.common.types.util.JavaReflectAccess.getConstructor(JavaReflectAccess.java:90) ~[na:na]
    at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateConstructorCall(XbaseInterpreter.java:511) ~[na:na]
    at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_73]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_73]
    at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
    at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
    at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateVariableDeclaration(XbaseInterpreter.java:601) ~[na:na]
    at sun.reflect.GeneratedMethodAccessor40.invoke(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_73]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_73]
    at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
    at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
    at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateBlockExpression(XbaseInterpreter.java:321) ~[na:na]
    at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_73]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_73]
    at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
    at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
    at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:204) ~[na:na]
    at org.openhab.model.script.internal.engine.ScriptImpl.execute(ScriptImpl.java:59) ~[na:na]
    at `org.openhab.core.scriptengine.ScriptExecutionThread.run(ScriptExecutionThread.java:44) ~[na:na]`

sorry for not posting it before but in the log files posts this error a few times and then posts only

2016-07-03 17:28:41.156 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ' fuzzy logic'
java.lang.NullPointerException: null

and I only saw the last posts.

This is how my .items file

Number HVACSETPOINTCHANGE "HVACSetPoint [%.3f]" <energy>    (GF_Corridor) {bacnet="100:2:10"}    
Switch HVACOnOff "HVACOnOff" <energy>    (GF_Corridor) {bacnet="100:2:11"}    
Number Mechanicalventilationchange "Ventilation [%.3f]" <energy>    (GF_Corridor) {bacnet="100:2:12"}

So has anynone any proposal on how should I work this out
??

As I said above, you usually get a completely different error when it can’t resolve a class name. Null exception implies that the imports are working and there is something else wrong with your rule.

Hi,
i’m using openhab-2.0.0 with Windows/Linux.
During rules execution i get this error “An error occured during the script execution: The name ‘ClientProtocolException’ cannot be resolved to an item or type”.
How can i add an external jar into rules classpath?
Thanks