KieScanner在Drools 6.1中不起作用 [英] KieScanner not working in Drools 6.1

查看:70
本文介绍了KieScanner在Drools 6.1中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用Drools规则集的Java应用程序.我们正在使用Drools 6.1.

We have a Java application that uses Drools rulesets. We are using Drools 6.1.

这些规则在工作台存储库中可用.当我们使用Workbench更改规则集时,我们希望看到结果的更改.因此,在我们的Java代码中,我们添加了Kiescanner模块,该模块会定期检查此机器,但无法成功.

The rules are available on the workbench repository. We want to see the changes in the results when we change the ruleset with Workbench. So, in our java code we added Kiescanner module that checks this machine periodically but we could not be successful.

我们的Java代码

package com.sample;

import org.drools.compiler.kproject.ReleaseIdImpl;
import org.kie.api.KieBase;
import org.kie.api.KieServices;
import org.kie.api.builder.KieScanner;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

import com.drools.project1.inputs;

/**
 * This is a sample class to launch a rule.
 */
public class DroolsTest {

public static final void main(String[] args) {

    try {
        KieServices ks = KieServices.Factory.get();

        ReleaseIdImpl releaseId = new ReleaseIdImpl("com.drools",
                "project1", "LATEST");

        KieContainer kieContainer = ks.newKieContainer(releaseId);

        KieScanner kieScanner = ks.newKieScanner(kieContainer);
        kieScanner.start(1000L);

        while (true) {

            KieBase kBase = kieContainer.getKieBase();

            KieSession kSession = kBase.newKieSession();

            inputs types = new inputs();

            types.setNum1(50);
            kSession.insert(types);
            kSession.fireAllRules();
            kSession.destroy();

            Thread.sleep(1000);
            System.out.println("getNum2 = " + types.getNum2());

        }

    } catch (Throwable t) {
        t.printStackTrace();

        System.err.println(t);
        System.err.println("Cause = " + t.getCause());
    }
}
}

我们通过以下方式创建了pom.xml和settings.xml文件.

We created our pom.xml and settings.xml files in the following way.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>com.sample</groupId>
<artifactId>DroolsMaven</artifactId>
<version>1.0.0-SNAPSHOT</version>

<name>Drools :: Sample Maven Project</name>
<description>A sample Drools Maven project</description>

<distributionManagement>
    <repository>
        <id>drools</id>
        <name>Internal Releases</name>
        <url>http://foo.com/kie-drools-wb-distribution/maven2</url>
    </repository>
</distributionManagement>

<dependencies>

    <!-- CDI dependencies -->
    <!-- END -->

    <dependency>
        <groupId>axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.4</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-ci</artifactId>
        <version>6.1.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.4</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.parsers</groupId>
        <artifactId>jaxp-api</artifactId>
        <version>1.4.5</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.org.apache</groupId>
        <artifactId>jaxp-ri</artifactId>
        <version>1.4</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>javax.xml.soap</groupId>
        <artifactId>javax.xml.soap-api</artifactId>
        <version>1.3.6</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>xerces</groupId>
        <artifactId>xerces</artifactId>
        <version>2.4.0</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.xml.rpc</artifactId>
        <version>3.1.1</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.3.2</version>
    </dependency>
    <dependency>
        <groupId>commons-discovery</groupId>
        <artifactId>commons-discovery</artifactId>
        <version>0.4</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.5</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.drools</groupId>
        <artifactId>project1</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/project1-1.0.jar</systemPath>
    </dependency>
</dependencies>


<repositories>
    <repository>
        <id>my-local-repo</id>
        <url>file://${project.basedir}/src/main/webapp/WEB-INF/lib</url>
    </repository>
</repositories>

<build>
    <extensions>
        <extension>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-ssh</artifactId>
            <version>2.4</version>
        </extension>
    </extensions>


    <finalName>NAME_OF_THE_GENERATED_WAR</finalName>
    <plugins>

        <plugin>
            <groupId>org.kie</groupId>
            <artifactId>kie-maven-plugin</artifactId>
            <version>6.1.0.Final</version>
            <extensions>true</extensions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <project>
                    1.6
                </project>
                <source>1.6</source>
                <target>1.6</target>
                <encoding>Cp1254</encoding>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <configuration>
                <encoding>Cp1254</encoding>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <outputDirectory>${basedir}/target/generatedWAR</outputDirectory>
                <tasks>
                    <echo>Echo : This is maven-war-plugin</echo>
                </tasks>
            </configuration>
        </plugin>
    </plugins>
</build>

</project>

settings.xml

settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>C:\Devel\m2repo</localRepository>

<pluginGroups>
</pluginGroups>

<proxies>
</proxies>

<servers>
    <server>
        <id>guvnor-m2-repo</id>
        <username>user</username>
        <password>pass</password>
    </server>
</servers>

<mirrors>
    <mirror>
        <id>guvnor-m2-repo</id>
        <url>http://foo.com/kie-drools-wb-distribution/maven2</url>
        <mirrorOf>*</mirrorOf>
    </mirror>

    <mirror>
        <id>nexus</id>
        <url>http://10.145.3.107:8081/nexus/content/groups/public</url>
        <mirrorOf>central</mirrorOf>
    </mirror>

    <mirror>
        <id>snapshots</id>
            <url>http://10.145.3.107:8081/nexus/content/repositories/snapshots</url>
        <mirrorOf>*</mirrorOf>
    </mirror>
</mirrors>

<profiles>
    <profile>
        <id>profile-1</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <repositories>
            <repository>
                <id>drools</id>
                <url>http://foo.com/kie-drools-wb-distribution/maven2</url>
                <releases>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </releases>
            </repository>
        </repositories>
    </profile>

    <profile>
        <id>a.profile</id>
        <properties>
            <a.property>this is a property</a.property>
        </properties>
    </profile>
    <profile>
        <id>b.profile</id>
        <properties>
            <b.property>this is another property</b.property>
        </properties>
    </profile>
</profiles>

<!-- activeProfiles | List of profiles that are active for all builds. | -->
<activeProfiles>
    <activeProfile>profile-1</activeProfile>
</activeProfiles>

</settings>

另一方面,如果在运行代码时删除本地存储库中的最新版本或"resolver-status.properties"文件,则新版本将自动从远程计算机下载到本地.但是,如果我们在Workbench上创建新版本,程序将无法检测到它.

On the other hand if we delete the latest version in the local repository or "resolver-status.properties" files when code is running, the new version is downloaded from remote machine to local automatically. However If we create a new version on Workbench, program doesn't detect it.

我们可以省略描述吗?

谢谢您的建议.

推荐答案

Dools 6.1是旧版本,与kieScanner可能存在一些问题.尝试使用最新版本的Drools(6.5),看看是否遇到相同的问题.

Dools 6.1 is old version, which may have some issues with kieScanner. Try with latest version of drools which is 6.5 and see if you encounter same issue or not.

这篇关于KieScanner在Drools 6.1中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆