I try to integrate Drools 7.4.1 into a webapp in tomcat.
When I call in the code the following statement to get a KieService I get
KieServices ks = KieServices.Factory.get();
When the same method is being called from a test method it is ok.
Can anyone help on this?droolskie
You have to add
drools-compiler in your dependencies.
<dependency> <groupId>org.drools</groupId> <artifactId>drools-compiler</artifactId> <version>7.4.1</version> </dependency>
We had the same issue when trying to use Drools in our webserver with embedded Grizzly http server.
We also needed to add the drools-compiler dependency, but that alone does not fix it.
Because there are multiple kie.conf files on the class path from the different dependencies, the uber-jar ends up having just one, and then definitions for classes to load are missing.
Besides these entries from the drools-core kie.conf:
org.kie.api.io.KieResources = org.drools.core.io.impl.ResourceFactoryServiceImpl org.kie.api.marshalling.KieMarshallers = org.drools.core.marshalling.impl.MarshallerProviderImpl org.kie.api.concurrent.KieExecutors = org.drools.core.concurrent.ExecutorProviderImpl
we added these lines from drools-compiler to our uber-jar kie.conf:
org.kie.api.KieServices = org.drools.compiler.kie.builder.impl.KieServicesImpl org.kie.internal.builder.KnowledgeBuilderFactoryService = org.drools.compiler.builder.impl.KnowledgeBuilderFactoryServiceImpl
Otherwise the KieServices were not loaded and KieServices.Factory.get() returned null.
We are modifying the built jar afterwards using
jar uf myjar.jar META-INF/kie.conf
to modify the contained kie.conf file. We couldn't find a clean integrated solution with Maven. Any suggestions welcome...
Thanks for the tip nicole.torres.
For this problem we can use the appendingtransformer avalaible in the maven-shade-plugin resource transformers:
Using this we can append all META-INF/kie.conf files. Anyone facing a null pointer when creating a KieBase or KieContainer in an ubber jar, visit this thread. I spent three days to find the solution and tried to create an ubber jar for almost every damn drools example available online :(