直接从存储库加载 Drools/KIE Workbench 工件 [英] Loading Drools/KIE Workbench artifacts directly from the repository

查看:26
本文介绍了直接从存储库加载 Drools/KIE Workbench 工件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们尝试使用全新的 KIE 工作台(以前称为 Guvnor)和基于 maven 的新工件切换到 Drools 6.

We try to switch to Drools 6 with the all new KIE workbench (formerly known as Guvnor) and the new maven-based artifacts.

现在我想使用中描述的系统第二张图片(部署")中的这篇博文:通过 HTTP 从工作台存储库加载规则(虚线箭头,从左侧的 HTTP 直接进入应用程序).

Now I'd like to use the the system described in this blog post in the second image ("Deployment"): Loading the rules via HTTP from the workbench repository (the dotted arrow, going from HTTP on the left directly into the application).

问题是,我不知道如何将工件加载到我的 KieServices/KieModule 对象中.我基本不想用maven,我也不能把maven的settings.xml的路径作为Java参数全局提供,所以这个选项没了.

The problem is, that I have no idea how to load the artifact into my KieServices/KieModule object. I basically do not want to use maven, I also cannot provide the path to maven's settings.xml globally as a Java parameter, so this option is out.

我认为类似的问题是这个.正如那里提到的,我也尝试加载一个 URL 资源,但问题似乎是系统无法确定给定 URL (http://localhost:8080/kie-drools/maven2/.../-1.0.0.jar) 是.是的,我可以直接从浏览器访问存储库中的 .jar,无需身份验证.

I think that a similar issue is this one. As mentioned there, I also tried to load an URL resource but the problem seems to be that the system cannot determine, what kind of ResourceType the given URL (http://localhost:8080/kie-drools/maven2/.../-1.0.0.jar) is. And yes, I can access the .jar from the repository directly from the browser, without authentication.

任何想法或教程如何做到这一点?

Any ideas or tutorials how to do this?

我的测试代码:

public static void main(String[] args) {
    KieServices ks = KieServices.Factory.get();
    KieRepository repo = ks.getRepository();

    String url = "http://localhost:8080/kie-drools/maven2/de/test/test/1.0.0/test-1.0.0.jar";

    Resource urlResource = ks.getResources().newUrlResource(url);
    KieModule kModule = repo.addKieModule(urlResource); // this already fails
}

错误:

Exception in thread "main" java.lang.RuntimeException: Unable to fetch module from resource :[UrlResource path='http://localhost:8080/kie-drools/maven2/de/itm/Herma400/1.0.1/Herma400-1.0.1.jar']
    at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:205)
    at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.addKieModule(KieRepositoryImpl.java:161)
    at kieTest.MainKieTest.main(MainKieTest.java:24)
Caused by: java.lang.NullPointerException
    at org.drools.compiler.kie.builder.impl.ClasspathKieProject.getPomProperties(ClasspathKieProject.java:197)
    at org.drools.compiler.kie.builder.impl.ClasspathKieProject.fetchKModule(ClasspathKieProject.java:148)
    at org.drools.compiler.kie.builder.impl.ClasspathKieProject.fetchKModule(ClasspathKieProject.java:109)
    at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:190)
    ... 2 more

提前致谢!

推荐答案

我终于设法解决了这个问题.下面是一个工作示例,它通过 HTTP 从 KIE 存储库加载 Drools 工件并执行规则:

I finally managed to get this solved. Below is a working example which loads the Drools artifact from the KIE-repository via HTTP and executes the rules:

package kieTest;

import java.util.Scanner;

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

public class MainKieTest {

    public static void main(String[] args) {

        // works even without -SNAPSHOT versions
        String url = "http://localhost:8080/kie-drools/maven2/de/test/Test/1.2.3/Test-1.2.3.jar";

        // make sure you use "LATEST" here!
        ReleaseIdImpl releaseId = new ReleaseIdImpl("de.test", "Test", "LATEST");

        KieServices ks = KieServices.Factory.get();

        ks.getResources().newUrlResource(url);

        KieContainer kieContainer = ks.newKieContainer(releaseId);

        // check every 5 seconds if there is a new version at the URL
        KieScanner kieScanner = ks.newKieScanner(kieContainer);
        kieScanner.start(5000L);
        // alternatively:
        // kieScanner.scanNow();

        Scanner scanner = new Scanner(System.in);
        while (true) {
            runRule(kieContainer);
            System.out.println("Press enter in order to run the test again....");
            scanner.nextLine();
        }
    }

    private static void runRule(KieContainer kieKontainer) {
        StatelessKieSession kSession = kieKontainer.newStatelessKieSession("testSession");
        kSession.setGlobal("out", System.out);
        kSession.execute("testRuleAgain");
    }
}

在搜索解决方案时,我发现以下链接很有帮助:

When searching for the solution, I found the following link helpful:

我希望有人在将 SO 作为第一个搜索结果时发现这很有用 ;-)

I hope someone finds this useful when getting SO as first search result ;-)

这篇关于直接从存储库加载 Drools/KIE Workbench 工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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