0

我想将 drools 工作台 6.4.0.Final 与我自己的应用程序集成。

以下是主要课程:

package com.example;
import com.idss.poc.CouponFact;
import com.idss.poc.Result;
import org.codehaus.plexus.util.FileUtils;
import org.drools.compiler.kie.builder.impl.KieServicesImpl;
import org.drools.compiler.kproject.ReleaseIdImpl;
import org.drools.core.io.impl.UrlResource;
import org.kie.api.KieServices;
import org.kie.api.builder.KieModule;
import org.kie.api.builder.KieRepository;
import org.kie.api.builder.KieScanner;
import org.kie.api.builder.ReleaseId;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.StatelessKieSession;
import org.kie.scanner.KieScannerFactoryServiceImpl;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class FunctionExample {
    public static void main(String[] args) {
        KieServices ks = KieServices.Factory.get();
        ReleaseId releaseId = ks.newReleaseId( "com.test", "poc", "LATEST" );

        KieContainer kContainer = ks.newKieContainer(releaseId);
        KieScanner kieScanner = ks.newKieScanner(kContainer);

        kieScanner.start( 10000L );

        Scanner scanner = new Scanner(System.in);

        while (true) {
            kieScanner.scanNow();
            String line = scanner.nextLine();
            runRule(kContainer);
        }
    }

    private static void runRule(KieContainer kieKontainer) {
        StatelessKieSession kSession =kieKontainer.newStatelessKieSession("ks");
        Result result = new Result();
        List<String> list = new ArrayList<String>();
        result.setRules(list);

        kSession.setGlobal("result", result);

        CouponFact cf = new CouponFact();
        cf.setPhoneCount(2);
        cf.setUserCount(2);
        cf.setDeviceCount(2);
        cf.setIp10mCount(10);
        cf.setIpDayCount(10);
        kSession.execute(cf);

        System.out.println(result.getScore() + "," + result.getRules());
    }
}

下面是我自己的应用程序使用的 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>~/.m2/repository</localRepository>
  <pluginGroups>
  </pluginGroups>
  <proxies>
  </proxies>
  <servers>
    <server>
      <id>guvnor-m2-repo</id>
      <username>workbench</username>
      <password>workbench!</password>
      <configuration>
        <wagonProvider>httpclient</wagonProvider>
        <httpConfiguration>
          <all>
            <usePreemptive>true</usePreemptive>
          </all>
        </httpConfiguration>
      </configuration>
    </server>
    <server>
      <id>mymirror</id>
      <username>workbench</username>
      <password>workbench!</password>
      <configuration>
        <wagonProvider>httpclient</wagonProvider>
        <httpConfiguration>
          <all>
            <usePreemptive>true</usePreemptive>
          </all>
        </httpConfiguration>
      </configuration>
    </server>
  </servers>
  <mirrors>
    <mirror>
      <id>mymirror</id>
      <url>http://10.10.10.57:8080/kie-wb/maven2</url>
      <mirrorOf>*</mirrorOf>
      <layout>default</layout>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>guvnor-m2-repo</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
            <id>guvnor-m2-repo</id>
            <name>Guvnor M2 Repo</name>
            <url>http://10.10.10.57:8080/kie-wb/maven2</url>
            <releases>
              <enabled>true</enabled>
            </releases>
            <updatePolicy>always</updatePolicy>
        </repository>
      </repositories>
    </profile>
  </profiles>
  <activeProfiles>
   <activeProfile>guvnor-m2-repo</activeProfile>
  </activeProfiles>
</settings>

当我在工作台中更新我的 drools 规则并升级我的 repo 版本时,但我的应用程序没有自动获取我的 repo 的最新版本。我得到这样的日志:

11:50:24.158 [Timer-0] DEBUG org.kie.scanner.embedder.MavenEmbedderUtils - Not in OSGi: using plexus based maven parser
11:50:24.212 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/pinter/Desktop/RiskGuard/~/.m2/repository
11:50:24.212 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/pinter/Desktop/RiskGuard/~/.m2/repository
11:50:24.213 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager - Using mirror mymirror (http://10.10.10.57:8080/kie-wb/maven2) for guvnor-m2-repo (http://10.10.10.57:8080/kie-wb/maven2).
11:50:24.215 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager - Using mirror mymirror (http://10.10.10.57:8080/kie-wb/maven2) for guvnor-m2-repo (http://10.10.10.57:8080/kie-wb/maven2).
11:50:24.215 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager - Using mirror mymirror (http://10.10.10.57:8080/kie-wb/maven2) for central (https://repo.maven.apache.org/maven2).
11:50:24.216 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultDependencyCollector - Dependency collection stats: {ConflictMarker.analyzeTime=0, ConflictMarker.markTime=0, ConflictMarker.nodeCount=1, ConflictIdSorter.graphTime=0, ConflictIdSorter.topsortTime=0, ConflictIdSorter.conflictIdCount=0, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=0, ConflictResolver.conflictItemCount=0, DefaultDependencyCollector.collectTime=0, DefaultDependencyCollector.transformTime=0}
11:50:24.217 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for ~/.m2/repository
11:50:24.217 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultUpdateCheckManager - Skipped remote request for com.idss:poc/maven-metadata.xml, locally cached metadata up-to-date.

谁能帮我弄清楚?谢谢!

4

3 回答 3

1

如果您LATEST在应用程序的版本号字段中使用,请KieScanner尝试将本地存储库中可用 jar 的版本号与 kie-workbench 中可用的 jar 版本号匹配。如果两个版本相同,则不会从远程存储库中获取 jar,而是使用本地存储库中的 jar。每次“构建和部署”时,请增加版本号以使更改反映在应用程序端。

如果每次部署时增加版本号对您来说工作量太大,我建议-SNAPSHOT在您的版本号中使用。即使本地存储库中有相同的版本,也始终从远程存储库中获取快照版本。<version>-SNAPSHOT应仅用于开发目的。

于 2016-08-15T06:05:31.500 回答
0

感谢@tarilabs@Naved Alam,您的回答对我有帮助。我阅读了 drools 文档,它告诉我:

如果 KieScanner 使用 SNAPSHOT、版本范围、最新或发布设置,则 KieScanner 只会拾取对已部署 jar 的更改。固定版本不会在运行时自动更新。

所以,我修改了我的工作台项目,并将版本号设置为2.0.0-SNAPSHOT,并更改了我的代码

ReleaseId releaseId = ks.newReleaseId( "com.test", "poc", "LATEST" );

ReleaseId releaseId = ks.newReleaseId( "com.test", "poc", "2.0.0-SNAPSHOT" );

到目前为止,它再次无法正常工作。该程序显示这样的日志:

11:50:24.158 [Timer-0] DEBUG org.kie.scanner.embedder.MavenEmbedderUtils - Not in OSGi: using plexus based maven parser
11:50:24.212 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/pinter/Desktop/RiskGuard/~/.m2/repository
11:50:24.212 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/pinter/Desktop/RiskGuard/~/.m2/repository
11:50:24.213 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager - Using mirror mymirror (http://10.10.10.57:8080/kie-wb/maven2) for guvnor-m2-repo (http://10.10.10.57:8080/kie-wb/maven2).
11:50:24.215 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager - Using mirror mymirror (http://10.10.10.57:8080/kie-wb/maven2) for guvnor-m2-repo (http://10.10.10.57:8080/kie-wb/maven2).
11:50:24.215 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager - Using mirror mymirror (http://10.10.10.57:8080/kie-wb/maven2) for central (https://repo.maven.apache.org/maven2).
11:50:24.216 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultDependencyCollector - Dependency collection stats: {ConflictMarker.analyzeTime=0, ConflictMarker.markTime=0, ConflictMarker.nodeCount=1, ConflictIdSorter.graphTime=0, ConflictIdSorter.topsortTime=0, ConflictIdSorter.conflictIdCount=0, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=0, ConflictResolver.conflictItemCount=0, DefaultDependencyCollector.collectTime=0, DefaultDependencyCollector.transformTime=0}
11:50:24.217 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for ~/.m2/repository
11:50:24.217 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultUpdateCheckManager - Skipped remote request for com.idss:poc/maven-metadata.xml, locally cached metadata up-to-date.

如我们所见,中央存储库https://repo.maven.apache.org/maven2已被我的自定义远程存储库http://10.10.10.57:8080/kie-wb/maven2覆盖。

我尝试更改我的 settings.xml,

<mirrors>
    <mirror>
      <id>mymirror</id>
      <url>http://10.10.10.57:8080/kie-wb/maven2</url>
      <mirrorOf>*</mirrorOf>
      <layout>default</layout>
    </mirror>
</mirrors>

<mirrors>
    <mirror>
      <id>mymirror</id>
      <url>http://10.10.10.57:8080/kie-wb/maven2</url>
      <mirrorOf>guvnor-m2-repo</mirrorOf>
      <layout>default</layout>
    </mirror>
</mirrors>

它工作正常!

于 2016-08-15T07:39:29.733 回答
0

我假设您输入“最新”是为了获取您的 KJAR 的最新快照版本。

如果是这种情况,我相信您需要将快照更新策略设置为大于“每日”默认值。updatePolicy此外,由于标签嵌套不正确,您的 Maven 设置文件中似乎有错误。我建议你尝试这样的事情:

  <profiles>
    <profile>
      <id>guvnor-m2-repo</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
            <id>guvnor-m2-repo</id>
            <name>Guvnor M2 Repo</name>
            <url>http://10.10.10.57:8080/kie-wb/maven2</url>

      <releases>
        <enabled>false</enabled>
        <updatePolicy>always</updatePolicy>
      </releases>
      <snapshots>
        <enabled>true</enabled>
        <updatePolicy>always</updatePolicy>
      </snapshots>

        </repository>
      </repositories>
    </profile>
  </profiles>

参考:https ://maven.apache.org/settings.html#Repositories

于 2016-08-08T10:00:20.023 回答