Pregunta

I have as setup where I'm using Drools Spring KnowledgeAgent to load rules from external path. The path contains DRL files at the moment, so the rules are compiled on the fly. For some reason I cannot get the rules to detect my facts, no matter where they are declared. I've used the following approaches, and keep on getting ClassNotFoundException / NoClassDefFoundException

  1. External fact model, i.e. Java classes
  2. External DRL file containing the facts
  3. Facts declared within the same DRL as the rule

I would need to get all of the above cases working.

My Spring configurations for the KnowledgeAgent is like

<!-- For scanning the changes -->
<drools:resource-change-scanner id="scanner" interval="10" />

<drools:kagent id="ruleAgent" kbase="ruleKBase" new-instance="true" >
  <drools:resources>
    <drools:resource source="file://external/path/rules/>
  </drools:resources>
</drools:kagent>

<!-- For starting the resource scanner -->
<bean id="starter" class="study.ResourceChangeScannerStarter" depends-on="ruleAgent" />

My DRLs containing rules and facts are in the path //external/path/rules. If I remove all references to facts and have a rule that has no LHS conditions, I get simple printouts on console, so I can verify that the rules are loaded just fine.

I'm using Drools 5.5.0

¿Fue útil?

Solución

OK. I got it working a bit better by using KnowledgeBuilder to create a package(ResourceType.PKG) from the rules and using that as an URL resource for KnowledgeAgent. Yet, there were so many problems with this whole setup, so I ended writing my own implementation.

Basically what I have is a class that

  1. Looks for files in the external path
  2. Adds all rule files as resources to KnowledgeBuilder
  3. Adds knowledge packages from builder to KnowledgeBase
  4. Creates new stateless session from KnowledgeBase

The only thing I have in spring config is kBase, which I get with Spring nicely to my custom class

<drools:kbase id="ruleKnowledgeBase">
</drools:kbase>

Marking my own question answered as to me the case is closed.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top