2017-04-14 88 views
0

我們有一個使用Drools規則集的Java應用程序。我們正在使用Drools 6.1。KieScanner不能在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上創建新版本,程序不會檢測到它。

我們能否做出缺失的描述?

謝謝你的建議。

回答

0

Dools 6.1是舊版本,它可能與kieScanner有一些問題。試試最新版本的6.5版本的drools,看看是否遇到同樣的問題。

相關問題