Search code examples
droolsrule-engine

Drools HelloWorld sample application gives error


When I first set up the sample hello world application I get errors in the rules/sample.drl files

The error is as follows:

Rule Compilation error Only a type can be imported. com.sample.DroolsTest.Message resolves to a package
Only a type can be imported. org.drools.core.spi.KnowledgeHelper resolves to a package
KnowledgeHelper cannot be resolved to a type
com.sample.DroolsTest.Message cannot be resolved to a type
org.kie.api.runtime.rule.FactHandle cannot be resolved to a type
org.kie.api.runtime.rule.FactHandle cannot be resolved to a type
java.lang.Exception cannot be resolved to a type
org.kie.api.runtime.rule.RuleContext cannot be resolved to a type
Message.GOODBYE cannot be resolved to a type
org.drools.core.util.bitmask.AllSetBitMask cannot be resolved to a type
com.sample.DroolsTest.Message cannot be resolved to a type

Also I fixed the error when I write dialect "mvel"
but for some reason I am not okay with this quick fix.

Am I missing some plugin or dependencies? I am a newbie to drools rule engine and I followed all steps correctly.


Solution

  • Yes the most possible explanation is that you have missed some depedencies.

    You need to include drools-core for example:

    Only a type can be imported. org.drools.core.spi.KnowledgeHelper resolves to a package
    

    suggests that Rules does not have access to KnowledgeHelper and tries to import it as a package. Same thing happens with:

    org.kie.api.runtime.rule.RuleContext
    

    and kie-api depedency.

    If you use Eclipse or some other IDE and started a new drools project then maybe drools library is not in build path.