2016-08-08 58 views
0

我想將drools工作臺6.4.0.Final與我自己的應用程序集成。KieScanner無法自動獲取最新版本!

下面這是主類:

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> 

當我更新我的滴料的工作臺治,提升我回購的版本,但我的應用程序不會自動讓我回購的最新版本。 我得到的日誌是這樣的:

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. 

誰能幫我弄明白?謝謝!

+0

升級版本的回購後,你「建立和部署」你的項目? –

+0

當然,我做了「構建和部署」我的項目。但它不起作用,我得到了舊版本。 – PINTER

回答

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

+0

它不起作用。 – PINTER

+0

從現在開始起作用。 – PINTER

1

如果您在版本號字段在你的應用程序中使用LATESTKieScanner嘗試匹配的jar的版本號可以在本地在kie-workbench提供版本號爲jar的倉庫。如果兩個版本都相同,則它不會從遠程存儲庫獲取jar並使用本地存儲庫中的jar。每次「構建和部署」時,都要增加版本號以使更改反映到應用程序端。

如果每次部署時增加版本號對您而言都是太多工作,我會建議在您的版本號中使用-SNAPSHOT。快照版本總是從遠程存儲庫獲取,即使本地存儲庫中有相同的版本。 <version>-SNAPSHOT應僅用於開發目的。

0

感謝@tarilabs@Naved Alam,你的答案只是幫助我。 我讀了Drools的文件,它告訴我:

的KieScanner只會皮卡更改已部署的罐子如果使用快照,版本範圍,最新的,或鬆開設置。固定版本不會在運行時自動更新。

所以,我修改了我的工作臺項目,並設置版本號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>guvnor-m2-repo</mirrorOf> 
     <layout>default</layout> 
    </mirror> 
</mirrors> 

這只是工作的罰款!