有没有办法在没有drools-compiler的情况下创建KieSession?

时间:2015-01-29 00:31:54

标签: drools kie

我正在尝试从我的项目中执行此代码以创建默认的kiesession:

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

但是,KieServices.Factory.get();失败了,因为:

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

我有一个预编译的kjar和kie-api作为我项目的依赖项。为什么我还需要drools-compiler?还有另一种创建ksession的方法,不需要我将drools-compiler添加到我的依赖项中(因为我的kjar已经编译了)?

这是尝试使用规则的项目的依赖部分:

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

1 个答案:

答案 0 :(得分:0)

KieServices不一定是DRL编译器。如果您查看此接口的API,您将看到它是实例化Kie提供的各种服务的入口点。

恰好将实现打包到jar中,其中保留了所有“构建”内容,包括DRL编译器。这并不意味着它实际上会被使用。