Is there any way to create a KieSession without drools-compiler?

FGreg Source

I am trying to execute this code from my project to create a default kiesession:

KieServices kieServices = KieServices.Factory.get();
KieContainer kContainer = kieServices.getKieClasspathContainer();
KieSession session = kContainer.newKieSession();

However, it fails on KieServices.Factory.get(); because:

Caused by: java.lang.RuntimeException: Unable to instance KieServices
            at org.kie.api.KieServices$Factory.<clinit>(KieServices.java:190)
            ... 63 more
Caused by: java.lang.ClassNotFoundException: org.drools.compiler.kie.builder.impl.KieServicesImpl
            at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:190)
            at org.kie.api.KieServices$Factory.<clinit>(KieServices.java:188)
            ... 63 more
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_67]
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_67]
   at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_67]
   at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
   ... 57 common frames omitted

I have a pre-compiled kjar and the kie-api as dependencies to my project. Why do I also need drools-compiler? Is there another way to create a ksession that does not require me to add drools-compiler to my dependencies (seeing as my kjar is already compiled)?

Here's the dependency portion of the project trying to use the rules:

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.project</groupId>
    <artifactId>my-project</artifactId>
    <version>0.1-SNAPSHOT</version>
    <name>my-project</name>
    <dependencies>
        <dependency>
            <groupId>my.project</groupId>
            <artifactId>my-rule-kjar</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-api</artifactId>
            <version>6.1.0.Final</version>
        </dependency>
    </dependencies>
</project>
droolskie

Answers

answered 4 years ago laune #1

KieServices isn't necessarily the DRL compiler. If you look at the API of this interface you'll see that it is the entry point for instantiating all kinds of services provided by Kie.

It so happens that the implementation is packed into the jar where all "building" stuff is kept, including the DRL compiler. This doesn't mean it will actually be used.

comments powered by Disqus