【问题标题】:Is there any way to create a KieSession without drools-compiler?有没有办法在没有流口水编译器的情况下创建 KieSession?
【发布时间】:2015-01-29 00:31:54
【问题描述】:

我正在尝试从我的项目中执行此代码以创建默认的 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?是否有另一种方法来创建不需要我将drools-compiler 添加到我的依赖项的ksession(因为我的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>

【问题讨论】:

  • 我了解 KieServices != DRL 编译器。但是,我需要在我的项目中添加一个名为 drools-compiler 的依赖项,而该依赖项没有编译任何内容,这非常违反直觉。

标签: drools kie


【解决方案1】:

KieServices 不一定是 DRL 编译器。如果你看一下这个接口的 API,你会发现它是实例化 Kie 提供的各种服务的入口点。

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

【讨论】:

    猜你喜欢
    • 2012-07-25
    • 2019-11-20
    • 2017-07-16
    • 2012-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    • 1970-01-01
    相关资源
    最近更新 更多