KieScanner不在Drools 6.1工作

时间:2017-04-14 07:23:44

标签: java xml maven drools drools-guvnor

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

规则可在工作台存储库中找到。我们希望在使用Workbench更改规则集时看到结果中的更改。所以,在我们的java代码中,我们添加了Kiescanner模块,它定期检查这台机器,但是我们无法成功。

我们的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文件。

的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

<?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上创建新版本,程序就不会检测到它。

我们可能缺少描述吗?

感谢您的建议。

1 个答案:

答案 0 :(得分:0)

Dools 6.1是旧版本,可能与kieScanner有一些问题。尝试6.5的最新版本的drools,看看你是否遇到同样的问题。