Drools 7.4.1 kieservices.factory.get() returns null

Kostas Karkaletsis Source

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 null.

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

Answers

answered 8 months ago freedev #1

You have to add drools-compiler in your dependencies.

    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-compiler</artifactId>
        <version>7.4.1</version>
    </dependency>

answered 4 months ago nicole.torres #2

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...

answered 4 months ago Carlos Costa #3

Thanks for the tip nicole.torres.

For this problem we can use the appendingtransformer avalaible in the maven-shade-plugin resource transformers:

https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#AppendingTransformer

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 :(

answered 1 month ago Ayaz Pasha #4

As suggested by @Carlos Costa, below changes in pom.xml solved the issue.

Summarizing all suggestions, below is the detailed solution. In pom.xml, add the following.

<dependencies>
  <dependency>
    <groupId>org.drools</groupId>
    <artifactId>drools-compiler</artifactId>
    <version>${runtime.version}</version>
  </dependency>
</dependencies>

And

<build>
  <plugins>
    <plugin>
      <executions>
        <execution>
          <configuration>
            <transformers>
              <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                <resource>META-INF/kie.conf</resource>
              </transformer>
            </transformers>
          </configuration>
       </execution>
     </executions>
    </plugin>
  </plugins>
</build>

answered 1 month ago S.Dayneko #5

You have to add this two dependencies and {version} of both dependencies must be the same

<dependency>
  <groupId>org.drools</groupId>
  <artifactId>drools-core</artifactId>
  <version>{version}</version>
</dependency>

<dependency>
  <groupId>org.drools</groupId>
  <artifactId>drools-compiler</artifactId>
  <version>{version}</version>
</dependency>

comments powered by Disqus